User:Ilmari Karonen/watchlisteditdoublesubmit.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.
// Add a second submit button to the top of [[Special:Watchlist/edit]]

if (mw.config.get('wgCanonicalNamespace') === "Special" && mw.config.get('wgCanonicalSpecialPageName') === "Watchlist") {
    $(function () {
        var form = document.getElementsByTagName("form")[0];
        if (!form || !/[?&]action=edit(&|$)/.test(form.getAttribute("action")))
            return;  // not the edit page
        var heading = document.getElementsByTagName("h2")[0];
        if (!heading) return;
        var buttonP = document.createElement("p");
        var inputs = form.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "submit") {
                buttonP.appendChild(inputs[i].cloneNode(true));
                heading.parentNode.insertBefore(buttonP, heading);
                return;
            }
        }
    });
}