User:DemonDays64/Scripts/Dumb quotes.js: Difference between revisions

Content deleted Content added
Line 1:
/*
// Make sure the utilities module is loaded (will only load if not already)
\\\Quick scripts///
* A rudimentary thing to copy and paste to make a regex find and replace script.
* To edit, go to editArticle() and edit makeAndRunRegex(). Call it again to add another search.
* Remember to set portledId, linkURL, linkText, and tooltip (along with the others if you want)
 
*/
mw.loader.using('mediawiki.util', function () {
 
$(document).ready(function () {
 
var portletId;
var linkUrl;
var linkText;
var linkId; //optional
var tooltip; //technically optional
var accessKey; //optional
 
var scriptLink = mw.util.addPortletLink(portletId, linkUrl, linkText, linkId, tooltip, accessKey);
$(dumbQuotesLinkscriptLink).click(function (event) {
event.preventDefault();
editArticle();
});
 
function setEditSummary(summary) {
document.editform.wpMinoredit.checked = true;
document.editform.wpTextbox1wpSummary.value = modifiedPagesummary;
doaction('diff');
}
 
function runRegex(regex) {
modifiedPage = modifiedPage.replace(regex.find, regex.replace);
}
 
function makeAndRunRegex(name, findRegex, replace) {
//add a tab on the left
var name = {
var dumbQuotesLink = mw.util.addPortletLink("p-tb", "#", "Dumb quotes", "t-dumb-quotes");
find: findRegex,
$(dumbQuotesLink).click(function (event) {
replace: replace
event.preventDefault();
}
setDumbQuotes();
runRegex(name);
});
}
 
function setEditSummarydoEdit() {
document.editform.wpMinoreditwpTextbox1.checkedvalue = truemodifiedPage;
}
document.editform.wpSummary.value = 'Replaced smart quotes with dumb. Problem? [[User talk:DemonDays64|Tell me]].';
doaction('diff');
}
function setDumbQuotes() {
var singleQuoteRegex = {
find: /(‘|’)/g,
replace: "'"
}
 
function showDiff() {
var doubleQuoteRegex = {
document.editform.diff();
find: /(“|”)/g,
}
replace: '"'
}
 
//EDIT HERE
var originalPage = document.editform.wpTextbox1.value;
function editArticle() {
var modifiedPage = originalPage;
var originalPage = document.editform.wpTextbox1.value;
var modifiedPage = originalPage;
 
modifiedPage = modifiedPage.replace makeAndRunRegex(singleQuoteRegex.find, singleQuoteRegex.replace/(‘|’)/g, "'");
modifiedPage = modifiedPage.replace makeAndRunRegex(doubleQuoteRegex.find, doubleQuoteRegex.replace/(“|”)/g, '"');
doEdit();
document.editform.wpTextbox1.value = modifiedPage;
setEditSummary("summary");
showDiff();
document.editform.diff();
}
}
});
});