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:05, 10 April 2020 (Fix problems). 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.
mw.loader.using('mediawiki.util', function () {

    $(document).ready(function () {

        var portletId;
        var linkUrl;
        var linkText;
        var linkId; //optional
        var tooltip; //technically optional
        var accessKey; //optional

        var scriptLink = mw.util.addPortletLink(portletId, linkUrl, linkText, linkId, tooltip, accessKey);
        $(scriptLink).click(function (event) {
            event.preventDefault();
            editArticle();
        });

        function setEditSummary(summary, isMinor) {
            document.editform.wpMinoredit.checked = isMinor;
            document.editform.wpSummary.value = summary;
        }

        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 showDiff() {
            document.editform.diff();
        }

        //EDIT HERE
        function editArticle() {
            makeAndRunRegex(singleQuoteRegex, /(‘|’)/g, "'");
            makeAndRunRegex(doubleQuoteRegex, /(“|”)/g, '"');

            makeAndRunRegex(/find (regex)/g, "replace");
            doEdit();
            setEditSummary("Replaced smart quotes with dumb. Error? [[User talk:DemonDays64|Tell me]].", true);
            showDiff();
        }
    });
});