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

Content deleted Content added
tooltip
Add note about regex
 
(30 intermediate revisions by 2 users not shown)
Line 1:
// See the documentation! Hope you like the script :-)
// Make sure the utilities module is loaded (will only load if not already)
// 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 () {
 
Line 12 ⟶ 15:
event.preventDefault();
editPage();
doaction("diff");
});
 
function runRegex(regex, thingToRegex) {
modifiedPage = modifiedPagethingToRegex.replace(regex.find, regex.replace);
}
 
Line 23 ⟶ 26:
replace: replace
};
runRegex(regexObject, modifiedPage);
}
 
function doEdit() {
document.editform.wpTextbox1.value = modifiedPage;
}
 
function setEditSummary(summary, isMinor) {
document.editform.wpMinoredit.checked = isMinor;
Line 40 ⟶ 45:
}
}
 
function showDiff() {
if(typeof doaction !== 'undefined') doaction("diff");
}
 
function editPage() {
pageBeforeEdit = document.editform.wpTextbox1.value;
modifiedPage = pageBeforeEdit;
 
makeAndRunRegex(/(?<!File:[^\]]*[^\]]*)(‘|’)/g, "'");
makeAndRunRegex(/(?<!File:[^\]]*[^\]]*)(“|”)/g, '"');
doEdit();
setEditSummary("Replaced smartcurly quotes with dumb.straight Problem?with [[User talk:DemonDays64/Scripts/Dumb quotes.js|Tellscript]] meper [[MOS:CQ]].", true);
showDiff();
}
});
});