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 02:32, 9 April 2020 (based on Wikipedia:User scripts/Guide thanks!). 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.
// 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-cactions', '#', 'Dumb quotes', 'ca-dumb-quotes', 'Replace smart quotes with dumb'); 
        $(dumbQuotesLink).click( function ( event ) {
            event.preventDefault();
            setDumbQuotes();

        } );
        
        function setEditSummary(){
			setoptions(minor='true'); 		
			setreason('Replaced smart quotes with dumb. Problem? [[User talk:DemonDays64|Tell me]].', 'append');
			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();
		    doaction('diff');
		}
    } );
} );