Jump to content

User:Mesidast/Curly Quotes.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mesidast (talk | contribs) at 10:12, 5 December 2022 (Version 1.0). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
//
// This script replaces curly quotes (“”‘’) with straight quotes ("') per the
// guidance at [[MOS:CURLY]].
//
// Forked from [[User:GorillaWarfare/script/curlies.js]] 

/**
* 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, "'");
				if (txtBefore !== editor.get()) {
					editor
						.options({ minor: true })
						.appendEditSummary("Replaced curly quotes per [[MOS:CURLY]] using [[User:Mesidast/Curly Quotes.js|a script]]")
						.clickDiff();
				} else {
					mw.notify("No changes made | Curly Quotes");
				}
			}
		},
	]);
});
// </nowiki>