User:DemonDays64/Scripts/Dumb quotes.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:DemonDays64/Scripts/Dumb quotes. |
// !!!!!!!! IMPORTANT !!!!!!!!
// When installed at [[Special:MyPage/common.js]]
// if you want to have it edit foreign characters (i.e. ‹single guillemets›, «double guillemets», and „comma-level quotes”)
// 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 () {
$(document).ready(function () {
var pageBeforeEdit;
var modifiedPage;
var previousSummary;
if (editOtherQuotes == null) {
var editOtherQuotes = false;
}
//add a tab on the left
var dumbQuotesLink = mw.util.addPortletLink("p-tb", "#", "Dumb quotes", "t-dumb-quotes", "Convert curly to straight quotes");
$(dumbQuotesLink).click(function (event) {
event.preventDefault();
editPage();
});
function runRegex(regex) {
modifiedPage = modifiedPage.replace(regex.find, regex.replace);
}
function makeAndRunRegex(findRegex, replace) {
var regexObject = {
find: findRegex,
replace: replace
};
runRegex(regexObject);
}
function doEdit() {
document.editform.wpTextbox1.value = modifiedPage;
}
function setEditSummary(summary, isMinor) {
document.editform.wpMinoredit.checked = isMinor;
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() {
doaction("diff");
}
function editPage() {
pageBeforeEdit = document.editform.wpTextbox1.value;
modifiedPage = pageBeforeEdit;
//‘Single smart quotes’
makeAndRunRegex(/(‘|’)/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("Standardized quote styles with [[User:DemonDays64/Scripts/Dumb quotes.js|script]] per [[MOS:CQ]]", true);
showDiff();
}
});
});