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 03:57, 10 April 2020 (Switch to User:DemonDays64/Scripts/Quick scripts.js to test). 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.
/*
                                \\\Quick scripts///
* A rudimentary thing to copy and paste to make a regex find and replace script.
* To edit, go to editArticle() and edit makeAndRunRegex(). Call it again to add another search.
* Remember to set portledId, linkURL, linkText, and tooltip (along with the others if you want)

*/
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) {
            document.editform.wpMinoredit.checked = true;
            document.editform.wpSummary.value = summary;
            doaction('diff');
        }

        function runRegex(regex) {
            modifiedPage = modifiedPage.replace(regex.find, regex.replace);
        }

        function makeAndRunRegex(name, findRegex, replace) {
            var name = {
                find: findRegex,
                replace: replace
            }
            runRegex(name);
        }

        function doEdit() {
            document.editform.wpTextbox1.value = modifiedPage;
        }

        function showDiff() {
            document.editform.diff();
        }

        //EDIT HERE
        function editArticle() {
            var originalPage = document.editform.wpTextbox1.value;
            var modifiedPage = originalPage;

            makeAndRunRegex(singleQuoteRegex, /(‘|’)/g, "'");
            makeAndRunRegex(doubleQuoteRegex, /(“|”)/g, '"');
            doEdit();
            setEditSummary("summary");
            showDiff();
        }
    });
});