Jump to content

User:MBisanz/monobookrfa.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.
importScript('User:Animum/urlparameters.js');

function addrfacatlinks() {
    var href_ = location.href.replace(/\/wiki\//i, "/w/index.php?title=");
    var href = href_ + "&action=edit&rfacat=";
    mw.util.addPortletLink("p-cactions", href + "redir", "redir", "ca-redir");
    mw.util.addPortletLink("p-cactions", href + "success", "success", "ca-success");
    mw.util.addPortletLink("p-cactions", href + "failed", "unsuccessful", "ca-failed");
}

if(document.title.indexOf("Wikipedia:Requests for adminship/") != -1) addOnloadHook(addrfacatlinks);

function decodeURLParams(param) {
    switch(param) {
        case "redir"   : return "[[:Category:Redirects to requests for adminship]]";
            break;
        case "success" : return "[[:Category:Successful requests for adminship]]";
            break;
        case "failed"  : return "[[:Category:Unsuccessful requests for adminship]]";
            break;
    }
}

addOnloadHook(function() {
    if(document.title.indexOf("Editing Wikipedia:Requests for adminship/") != -1 && UrlParameters["action"] == "edit" && typeof(UrlParameters["rfacat"]) != 'undefined') {
        if(document.forms["editform"].wpTextbox1.value.indexOf("[[:Category:Redirects to requests for adminship]]") != -1 || document.forms["editform"].wpTextbox1.value.indexOf("[[:Category:Successful requests for adminship]]") != -1 || ["editform"].wpTextbox1.value.indexOf("[[:Category:Unsuccessful requests for adminship]]") != -1) {
            jsMsg('<center><b><big>This RfA has already been categorized.</big></b></center>');
        } else {
            var cat = decodeURLParams(UrlParameters["rfacat"]);
            document.forms["editform"].wpTextbox1.value += "\n" + cat;
            document.forms["editform"].wpSummary.value = "Script-assisted categorization";
            document.forms["editform"].wpMinoredit.checked = false;
            document.forms["editform"].submit(); //Submit
        }
    }
});