Jump to content

User:Animum/count.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Animum (talk | contribs) at 02:34, 10 February 2008 (remove quotes). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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');

addOnloadHook(function() { 
  var subpagename = wgTitle.split( '/' )[1];
  if( (wgNamespaceNumber == 2 || wgNamespaceNumber == 3 || ( wgNamespaceNumber == -1 && wgTitle == 'Contributions' )) && !subpagename ) { 
    if( wgNamespaceNumber == -1 && wgTitle == 'Contributions') {
     if(!document.getElementById( 'contentSub' )) return; 
    addToolboxLink('javascript:docountedit()', "Edit count", '', '', ''); 
    }
  } 
});

function docountedit() {
 var subpagename = wgTitle.split( '/' )[1];
  if( (wgNamespaceNumber == 2 || wgNamespaceNumber == 3 || ( wgNamespaceNumber == -1 && wgTitle == 'Contributions' )) && !subpagename ) { 
    var countuser = wgTitle.split( '/' )[0];
    if( wgNamespaceNumber == -1 && wgTitle == 'Contributions') {
     if(!document.getElementById( 'contentSub' )) return; 
    countuser = document.getElementById( 'contentSub' ).getElementsByTagName( 'a' )[0].getAttribute('title').split(':')[1];
    }
    var req = new XMLHttpRequest();
    req.open("GET", "http://en.wikipedia.org/w/api.php?action=query&list=users&usprop=editcount&ususers=" + encodeURIComponent(countuser), true);

    req.onreadystatechange = function() { 
      if (req.readyState == 4 && req.status == 200) {
       var user = req.responseXML.getElementsByTagName('user');
       var count = user.getAttribute('editcount');
       if(user.getAttribute('missing') == undefined) /* The user exists, no? */ alert(user.getAttribute('name') + " has " + count + " surviving edit" + (count == 1 ? "." : "s."));
      } 
    }
    req.send();
  }
}

//</nowiki></pre>