User:Animum/count.js

Source: 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.
//<pre><nowiki>
importScript('User:Voice of All/Addtabs/monobook.js');

function retrieveData(user) {
    var req = sajax_init_object();
    req.open("GET", "http://en.wikipedia.org/w/api.php?format=json&action=query&list=users&usprop=editcount&ususers=" + user, false);
    req.send(null);
    var info = eval("(" + req.responseText + ")").query.users[0];
    var editcount = info.editcount;
    var name = info.name;
    document.getElementById("contentSub").innerHTML += "<br /><b>" + name + " has " + editcount + " total edits.";
}

function editcount() { 
    var subpagename = mw.config.get('wgTitle').split('/')[1];
    if((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) && !subpagename) { 
        var countuser = mw.config.get('wgTitle');
        retrieveData(countuser);
    }
    if(mw.config.get('wgNamespaceNumber') == '-1' && mw.config.get('wgTitle') == 'Contributions') {
        if(!document.getElementById('contentSub')) return; 
        countuser = document.title.split("for ")[1].split(" - ")[0];
        retrieveData(countuser);
    }
}

function addcountedit() { 
    var subpagename = mw.config.get('wgTitle').split( '/' )[1];
    if(((mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3) && typeof(subpagename) == "undefined") || mw.config.get('wgCanonicalSpecialPageName') == "Contributions") { 
        mw.util.addPortletLink("p-cactions", "javascript:editcount()", String.fromCharCode(47), "ca-editcount");
    } 
}

$(addcountedit);

//</nowiki></pre>