Jump to content

User:Sander Säde/editcount.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.
addOnloadHook(doQuickCount);

function doQuickCount() {
  if (mw.config.get('wgPageName') == "Special:Contributions") {
    var name = document.getElementById("contentSub").getElementsByTagName("a"); 
    var rname = name[0].innerHTML;    
    if (rname == "talk") return; //IP
    var cnteraj = sajax_init_object(null);
    cnteraj.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=users&ususers=" + rname + "&usprop=editcount&format=json", true);
    cnteraj.onreadystatechange = function()
    {
      if(cnteraj.readyState != 4) return;
      var response = eval('(' + cnteraj.responseText + ')');
      var count = response["query"]["users"][0]["editcount"];    
      document.getElementById("contentSub").innerHTML = document.getElementById("contentSub").innerHTML + "&nbsp;·&nbsp;<span id='quickEditCount'>Edit count: " + count + "</span>";        
    };
    cnteraj.send(null);
  }
}