User:Mesidast/Curly 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:Mesidast/Curly Quotes. |
// <nowiki>
//
// Forked from [[User:GorillaWarfare/script/curlies.js]]
// Forked by [[User:Mesidast]]. For full list of changes see [[User:Mesidast/Curly Quotes]]
// Version 1.1
//
// This script replaces curly quotes (“”‘’) with straight quotes ("') per the guidance at [[MOS:CURLY]].
/**
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
* @see https://meta.wikimedia.org/wiki/TemplateScript
* @update-token [[File:Pathoschild/templatescript.js]]
*/
$.ajax("//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js", { dataType:"script", cache:true }).then(function() {
pathoschild.TemplateScript.add([
{
name: "Curly Quotes",
script: function(editor) {
var txtBefore = editor.get();
editor
.replace(/[“”]/g, '"')
.replace(/[‘’]/g, "'");
var filesBefore = txtBefore.match(/\[\[(?:file|image):.+?(?:\||\]\])/gi) || [];
var filesAfter = editor.get().match(/\[\[(?:file|image):.+?(?:\||\]\])/gi) || [];
if ((new Set(filesBefore)).size == (new Set(filesAfter)).size) {
for (var i = 0; i < filesBefore.length; i++) {
if (filesBefore[i] !== filesAfter[i]) {
editor.replace(filesAfter[i], filesBefore[i]);
}
}
} else {
mw.notify("CHECK FILE NAMES BEFORE SUBMITTING this edit. Some file names have been changed and could not be restored as they now match another file name | Curly Quotes");
}
if (txtBefore !== editor.get()) {
editor
.options({ minor: true })
.appendEditSummary("Replaced curly quotes per [[MOS:CURLY]] using [[User:Mesidast/Curly Quotes|a script]]")
.clickDiff();
} else {
mw.notify("No changes made | Curly Quotes");
}
}
},
]);
});
// </nowiki>