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

Content deleted Content added
Does htis work at all
Add note about regex
 
(21 intermediate revisions by 2 users not shown)
Line 1:
// See the documentation! Hope you like the script :-)
/** NOTE: To avoid changing the unusual styles of quotation marks such as «»
// NOTE: Uses a regex feature implemented fairly recently in some browsers (https://caniuse.com/?search=Lookbehind):
* set the variable basic to false.
// Chrome: 10/2017 | Firefx: 6/2020 | Edge: 1/2020 | Safari: 3/2023 | Opera: 11/2017
* Do this by adding this line:
// 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.
* basic = true;
* to your common.js file ([[Special:MyPage/common.js]]).
*/
// Make sure the utilities module is loaded (will only load if not already)
mw.loader.using('mediawiki.util', function () {
 
Line 12 ⟶ 9:
var modifiedPage;
var previousSummary;
var basic = true;
 
//add a tab on the left
Line 20 ⟶ 16:
editPage();
});
 
function runRegex(regex, thingToRegex) {
modifiedPage = modifiedPagethingToRegex.replace(regex.find, regex.replace);
}
 
Line 29 ⟶ 26:
replace: replace
};
runRegex(regexObject, modifiedPage);
}
 
function doEdit() {
document.editform.wpTextbox1.value = modifiedPage;
}
 
function setEditSummary(summary, isMinor) {
document.editform.wpMinoredit.checked = isMinor;
Line 46 ⟶ 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, '"');
 
if (!basic) {
//‹Single guillemets›
makeAndRunRegex(/(‹|›)/g, "'");
//«Double guillemets»
makeAndRunRegex(/(«|»)/g, '"');
 
//‚Single down quotes‘
makeAndRunRegex(/‚/g, "'");
//„Double down quotes“
makeAndRunRegex(/„/g, '"');
 
//`Backticks´
makeAndRunRegex(/(`|´)/g, '"');
}
 
doEdit();
setEditSummary("Replaced smartcurly quotes with dumbstraight with [[User:DemonDays64/Scripts/Dumb quotes.js|script]] per [[MOS:CQ]]. Problem? [[User talk:DemonDays64|Tell the author]]", true);
showDiff();
}
}
});
});