Jump to content

User:DemonDays64/Scripts/Dumb quotes.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DemonDays64 (talk | contribs) at 04:09, 10 April 2020 (Revert to https://en.wikipedia.org/w/index.php?title=User:DemonDays64/Scripts/Dumb_quotes.js&oldid=950073978). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Make sure the utilities module is loaded (will only load if not already)
mw.loader.using('mediawiki.util', function () {

	$(document).ready(function () {

		//add a tab on the left
		var dumbQuotesLink = mw.util.addPortletLink("p-tb", "#", "Dumb quotes", "t-dumb-quotes");
		$(dumbQuotesLink).click(function (event) {
			event.preventDefault();
			setDumbQuotes();
		});

		function setEditSummary() {
			document.editform.wpMinoredit.checked = true;
			document.editform.wpSummary.value = 'Replaced smart quotes with dumb. Problem? [[User talk:DemonDays64|Tell me]].';
			doaction('diff');
		}
		function setDumbQuotes() {
			var singleQuoteRegex = {
				find: /(‘|’)/g,
				replace: "'"
			}

			var doubleQuoteRegex = {
				find: /(“|”)/g,
				replace: '"'
			}

			var originalPage = document.editform.wpTextbox1.value;
			var modifiedPage = originalPage;

			modifiedPage = modifiedPage.replace(singleQuoteRegex.find, singleQuoteRegex.replace);
			modifiedPage = modifiedPage.replace(doubleQuoteRegex.find, doubleQuoteRegex.replace);
			document.editform.wpTextbox1.value = modifiedPage;
			setEditSummary();
			document.editform.diff();
		}
	});
});