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

Content deleted Content added
Testing
Add note about regex
 
(8 intermediate revisions by 2 users not shown)
Line 1:
// See the documentation! Hope you like the script :-)
// !!!!!!!! IMPORTANT !!!!!!!!
// NOTE: Uses a regex feature implemented fairly recently in some browsers (https://caniuse.com/?search=Lookbehind):
// When installed at [[Special:MyPage/common.js]]
// Chrome: 10/2017 | Firefx: 6/2020 | Edge: 1/2020 | Safari: 3/2023 | Opera: 11/2017
// if you want to have it edit foreign characters (i.e. ‹single guillemets›, «double guillemets», and „comma-level quotes”)
// 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.
// YOU MUST PUT THE FOLLOWING LINE ON THE PAGE **BEFORE** THE LINE TO IMPORT Dumb quotes.js:
/*
 
var editOtherQuotes = true;
 
*/
// otherwise only standard curly quotes and backticks will be fixed.
 
mw.loader.using('mediawiki.util', function () {
 
Line 16 ⟶ 9:
var modifiedPage;
var previousSummary;
 
//add a tab on the left
Line 24 ⟶ 16:
editPage();
});
 
function runRegex(regex, thingToRegex) {
modifiedPage = modifiedPagethingToRegex.replace(regex.find, regex.replace);
}
 
Line 33 ⟶ 26:
replace: replace
};
runRegex(regexObject, modifiedPage);
}
 
function doEdit() {
document.editform.wpTextbox1.value = modifiedPage;
}
 
function setEditSummary(summary, isMinor) {
document.editform.wpMinoredit.checked = isMinor;
Line 50 ⟶ 45:
}
}
 
function showDiff() {
if(typeof doaction !== 'undefined') doaction("diff");
}
 
function editPage() {
pageBeforeEdit = document.editform.wpTextbox1.value;
modifiedPage = pageBeforeEdit;
 
makeAndRunRegex(/(?<!File:[^\]]*[^\]]*)(‘|)/g, "'");
//‘Single smart quotes’
makeAndRunRegex(/(?<!File:[^\]]*[^\]]*)(“|)/g, "'"');
//“Double smart quotes”
makeAndRunRegex(/(“|”)/g, '"');
 
//`Backticks´
makeAndRunRegex(/(`|´)/g, '"');
 
if (editOtherQuotes) {
//‹Single guillemets›
makeAndRunRegex(/(‹|›)/g, "'");
//«Double guillemets»
makeAndRunRegex(/(«|»)/g, '"');
 
//‚Single down quotes‘
makeAndRunRegex(/‚/g, "'");
//„Double down quotes“
makeAndRunRegex(/„/g, '"');
}
 
doEdit();
setEditSummary("StandardizedReplaced quotecurly stylesquotes with straight with [[User:DemonDays64/Scripts/Dumb quotes.js|script]] per [[MOS:CQ]].", true);
showDiff();
}
});
});