Jump to content

User:Animum/easyblock.js/parseUsers.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.
//This tool is to help me see how many admins have EasyBlock installed.
//It uses [[Special:WhatLinksHere/User:Animum/easyblock.js]] for most of the work.

function parseusers() {
    var node = document.getElementById("bodyContent").getElementsByTagName("li");
    var counter = 0;
    for(i=0;i<node.length;i++) {
        var nodetext = node[i].getElementsByTagName("a")[0].innerHTML;
        if(nodetext.search(/monobook\.js/) != -1) {
            var name = nodetext.split("User:")[1].split("/")[0];
            var req = sajax_init_object();
            req.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=allusers&auprop=groups&aulimit=1&format=json&aufrom=" + name, false);
            req.send(null);
            var data = eval("(" + req.responseText + ")").query.allusers[0];
            if(data) { 
                if(data.groups) {
                    if(data.groups.indexOf("sysop") == -1) {
                        node[i].style.display = "none";
                        counter = counter+1;
                    } else {
                        node[i].innerHTML += " <b>(" + ((i+1)-counter) + ")</b>";
                    }
                } else {
                    node[i].style.display = "none";
                    counter = counter+1;
                }
            }
        } else {
            node[i].style.display = "none";
            counter = counter+1;
        }
    }
}

$(function() {
    if(document.title == 'Pages that link to "User:Animum/easyblock.js" - Wikipedia, the free encyclopedia') {
        mw.util.addPortletLink("p-cactions", "javascript:parseusers()", "parse", "ca-parse");
    }
});