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

Content deleted Content added
Add note about regex
 
(46 intermediate revisions by 2 users not shown)
Line 1:
// See the documentation! Hope you like the script :-)
/*
// NOTE: Uses a regex feature implemented fairly recently in some browsers (https://caniuse.com/?search=Lookbehind):
\\\Quick scripts///
// Chrome: 10/2017 | Firefx: 6/2020 | Edge: 1/2020 | Safari: 3/2023 | Opera: 11/2017
* A rudimentary thing to copy and paste to make a regex find and replace script.
// If running older browsers I believe it will work normally except that it will modify File links. The previous versions did not have this feature and used widely-supported Regex.
* 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 pageBeforeEdit;
 
var modifiedPage;
var portletId;
var previousSummary;
var linkUrl;
var linkText;
var linkId; //optional
var tooltip; //technically optional
var accessKey; //optional
 
//add a tab on the left
var scriptLink = mw.util.addPortletLink(portletId, linkUrl, linkText, linkId, tooltip, accessKey);
var dumbQuotesLink = mw.util.addPortletLink("p-tb", "#", "Dumb quotes", "t-dumb-quotes", "Convert curly to straight quotes");
$(scriptLinkdumbQuotesLink).click(function (event) {
event.preventDefault();
editArticle();
editPage();
});
});
 
function setEditSummaryrunRegex(summaryregex, thingToRegex) {
modifiedPage = modifiedPagethingToRegex.replace(regex.find, regex.replace);
document.editform.wpMinoredit.checked = true;
}
document.editform.wpSummary.value = summary;
doaction('diff');
}
 
function runRegexmakeAndRunRegex(regexfindRegex, replace) {
var regexObject = {
modifiedPage = modifiedPage.replace(regex.find, regex.replace);
find: findRegex,
}
replace: replace
};
runRegex(regexObject, modifiedPage);
}
 
function makeAndRunRegexdoEdit(name, findRegex, replace) {
document.editform.wpTextbox1.value = modifiedPage;
var name = {
}
find: findRegex,
replace: replace
}
runRegex(name);
}
 
function doEditsetEditSummary(summary, isMinor) {
document.editform.wpTextbox1wpMinoredit.valuechecked = modifiedPageisMinor;
previousSummary = document.editform.wpSummary.value;
}
if (previousSummary !== "") {
if (!previousSummary.includes(summary)) {
document.editform.wpSummary.value = document.editform.wpSummary.value + " | " + summary;
}
}
else {
document.editform.wpSummary.value = summary;
}
}
 
function showDiff() {
if(typeof doaction !== 'undefined') doaction("diff");
document.editform.diff();
}
}
 
function editArticleeditPage() {
//EDIT HERE
var originalPage pageBeforeEdit = document.editform.wpTextbox1.value;
function editArticle() {
modifiedPage = pageBeforeEdit;
var originalPage = document.editform.wpTextbox1.value;
var modifiedPage = originalPage;
 
makeAndRunRegex(singleQuoteRegex, /(?<!File:[^\]]*[^\]]*)(‘|’)/g, "'");
makeAndRunRegex(doubleQuoteRegex, /(?<!File:[^\]]*[^\]]*)(“|”)/g, '"');
doEdit();
setEditSummary("Replaced curly quotes with straight with [[User:DemonDays64/Scripts/Dumb quotes.js|script]] per [[MOS:CQ]].", true);
setEditSummary("summary");
showDiff();
}
}
});
});
});