Jump to content

User:Fetchcomms/hangon.js

From Wikipedia, the free encyclopedia
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.
$(function () {
    var changeCSDToHangon = document.getElementById('hangonbutton');
    if (changeCSDToHangon) {
        try {
            mw.loader.load('https://secure.wikimedia.org/wikinews/en/w/index.php?title=user:Bawolff/mwapilib2.js&action=raw&ctype=text/javascript');
            var button = document.createElement('button');
            button.type = 'button';
            button.appendChild(changeCSDToHangon .firstChild.firstChild);
            changeCSDToHangon .replaceChild(button, changeCSDToHangon .firstChild);
            button.onclick = function () {
                if (this && this.firstChild && this.firstChild.data) this.firstChild.data = "Loading ...";
                api(wgPageName).getPage().
                    setDefaultSummary("Please do not delete this page yet").
                    replace(/^/, "\{\{hangon}}\n").
                    savePage().
                    lift(function () {
                        alert("A \"hang on\" notice has been added to the page. This will alert administrators that you disagree with this speedy deletion request, but you MUST also explain why you believe this page should not be deleted on the next page.");
                        if (wgNamespaceNumber == 2) var talkPage = 'User talk:' + wgTitle;
                        else var talkPage = 'Talk:' + wgPageName;
                        window.location.href="http://en.wikipedia.org/w/index.php?action=edit&preload=Template%3AHangon+preload&editintro=User%3AFetchcomms/test/foo&preloadtitle=Contested+deletion&section=new&title=" + talkPage + "&create=Click+here+to+contest+this+speedy+deletion";
                    }).
                    exec();
            }
        }
        catch (e) {}
    }
});