User:Animum/usergroups.js

var usergroups = { "findRFA" : function(user) { var searchStr = new RegExp("adminship/" + user + "( [23456789]*)?\"\>", "i");       var req = sajax_init_object;        req.open("GET", mw.config.get('wgScript') + "?title=Category:Successful_requests_for_adminship&from=" + encodeURIComponent(user), false);        req.send(null);        with(req.responseText.split("")[1].split(" ")[0]) {            if(search(searchStr) == -1) {                var req2 = sajax_init_object;                req2.open("GET", mw.config.get('wgScript') + "?title=Category:Redirects_to_requests_for_adminship&from=" + encodeURIComponent(user), false);                req2.send(null);                var content = req2.responseText.split("")[1].split(" ")[0];                if(searchStr.test(content)) {                    var redirect = content.substring(content.search(searchStr)-23).split("\">")[0]; var req3 = sajax_init_object; req3.open("GET", mw.config.get('wgScript') + "?title=" + encodeURIComponent(redirect) + "&action=edit", false); req3.send(null); var content2 = req3.responseText.split("bodyContent")[1].split("visualClear")[0]; location.href = mw.config.get('wgArticlePath').replace(/\$1/g, content2.split(/\#REDIRECT ?\[\[/i)[1].split("]]")[0]); delete req3; } else { jsMsg("RfA was missing from Category:Successful requests for adminship and Category:Redirects to requests for adminship."); }               delete req2; } else { location.href = mw.config.get('wgArticlePath').replace(/\$1/g, substring(search(searchStr)-23).split("\">")[0]);           }        }        delete req;    },    "findRFB" : function(user) {        var req = sajax_init_object;        var searchStr = new RegExp("bureaucratship/" + user + "( [23456789]*)?\"\>", "i"); req.open("GET", mw.config.get('wgScript') + "?title=Category:Successful_requests_for_bureaucratship&from=" + encodeURIComponent(user), false); req.send(null); with(req.responseText.split("")[1].split(" ")[0]) { if(search(searchStr) != -1) { location.href = mw.config.get('wgArticlePath').replace(/\$1/g, substring(search(searchStr)-23).split("\">")[0]);           } else {                jsMsg("RFB was not found in Category:Successful requests for bureaucratship.");            }        }    },    "link" : function (link) {        switch(link) {            case "accountcreator": return "User_access_levels#Accountcreator";                break;            case "rollbacker"    : return "Rollback_feature";                break;            case "ipblock-exempt": return "User_access_levels#Ipblock-exempt";                break;            case "confirmed"     : return "User_access_levels#Confirmed";                break;            case "sysop"         : return "Administrators";                break;            case "oversight"     : return "Oversight"; break; case "checkuser"    : return "CheckUser"; break; case "bot"          : return "Bots"; break; case "bureaucrat"   : return "Bureaucrats"; break; case "abusefilter"  : return "Edit_filter"; break; default             : return "User_access_levels"; }   },    "download" : function { var target = mw.config.get('wgTitle'); if (mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgCanonicalSpecialPageName')=="Contributions") target = document.getElementsByName("target")[0].value; var req = sajax_init_object; req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&list=allusers&auprop=groups&aulimit=1&format=json&aufrom=" + encodeURIComponent(target), false); req.send(null); var data = eval("(" + req.responseText + ")").query.allusers[0]; if(data) { if(data.groups) { document.getElementById("contentSub").innerHTML += " " + target + " is " + (data.groups[0].substring(0, 1).search(/[aeiou]/) != -1 ? "an " : "a ") + ""; //Is the first letter of the first usergroup a vowel? If so, use "an"; if not, use "a." for(i=0; i<20; i++) { //Why 20? 20 is a high number. if(data.groups[i]) { document.getElementById("contentSub").innerHTML += "" + data.groups[i] + (data.groups[i] == "confirmed" ? " user" : "") + "" + (data.groups[i] == "sysop" ? " (RfA''')" : (data.groups[i] == "bureaucrat" ? " (RfB'''</a><b>)" : "")) + (!data.groups[i+1] ? "." : (data.groups.length == 2 ? " and " : ", " + (!data.groups[i+2] ? "and " : ""))) + "</b>"; } else { break; }               }            } else { document.getElementById("contentSub").innerHTML += " <b>" + target + " is not in any special user groups."; }       }    } };

$(function {   if(((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) && mw.config.get('wgPageName').indexOf("/") == -1) || (mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgCanonicalSpecialPageName') == "Contributions")) {        importStylesheet("User:Animum/usergroups.css");        mw.util.addPortletLink("p-cactions", "javascript:usergroups.download", "$", "ca-usergroups");    } });