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

Content deleted Content added
updated version
Add note about regex
 
(45 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):
// Chrome: 10/2017 | Firefx: 6/2020 | Edge: 1/2020 | Safari: 3/2023 | Opera: 11/2017
// 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.
mw.loader.using('mediawiki.util', function () {
 
$(document).ready(function () {
var pageBeforeEdit;
var modifiedPage;
var previousSummary;
 
//add a tab on the left
var portletId;
var dumbQuotesLink = mw.util.addPortletLink("p-tb", "#", "Dumb quotes", "t-dumb-quotes", "Convert curly to straight quotes");
var linkUrl;
$(scriptLinkdumbQuotesLink).click(function (event) {
var linkText;
event.preventDefault();
var linkId; //optional
editPage();
var tooltip; //technically optional
});
var accessKey; //optional
 
function runRegex(regex, thingToRegex) {
var scriptLink = mw.util.addPortletLink(portletId, linkUrl, linkText, linkId, tooltip, accessKey);
modifiedPage = modifiedPagethingToRegex.replace(regex.find, regex.replace);
$(scriptLink).click(function (event) {
}
event.preventDefault();
editArticle();
});
 
function setEditSummarymakeAndRunRegex(summaryfindRegex, isMinorreplace) {
var regexObject = {
document.editform.wpMinoredit.checked = isMinor;
find: findRegex,
document.editform.wpSummary.value = summary;
replace: replace
}
};
runRegex(regexObject, modifiedPage);
}
 
function runRegexdoEdit(regex) {
document.editform.wpTextbox1.value = modifiedPage;
modifiedPage = modifiedPage.replace(regex.find, regex.replace);
}
}
 
function makeAndRunRegexsetEditSummary(findRegexsummary, replaceisMinor) {
document.editform.wpMinoredit.checked = isMinor;
var regexObject = {
previousSummary = document.editform.wpSummary.value;
find: findRegex,
if (previousSummary !== "") {
replace: replace
if (!previousSummary.includes(summary)) {
}
document.editform.wpSummary.value = document.editform.wpSummary.value + " | " + summary;
runRegex(regexObject);
}
}
}
else {
document.editform.wpSummary.value = summary;
}
}
 
function doEditshowDiff() {
if(typeof doaction !== 'undefined') doaction("diff");
document.editform.wpTextbox1.value = modifiedPage;
}
}
 
function showDiffeditPage() {
pageBeforeEdit = document.editform.diff()wpTextbox1.value;
modifiedPage = pageBeforeEdit;
}
 
makeAndRunRegex(singleQuoteRegex, /(?<!File:[^\]]*[^\]]*)(‘|’)/g, "'");
//EDIT HERE
makeAndRunRegex(doubleQuoteRegex, /(?<!File:[^\]]*[^\]]*)(“|”)/g, '"');
function editArticle() {
doEdit();
makeAndRunRegex(singleQuoteRegex, /(‘|’)/g, "'");
setEditSummary("Replaced curly quotes with straight with [[User:DemonDays64/Scripts/Dumb quotes.js|script]] per [[MOS:CQ]].", true);
makeAndRunRegex(doubleQuoteRegex, /(“|”)/g, '"');
showDiff();
 
}
makeAndRunRegex(/find (regex)/g, "replace");
doEdit();
});
setEditSummary("summary", true);
showDiff();
}
});
});