Misplaced Pages

User:Animum/count.js: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:Animum Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 03:08, 10 February 2008 view sourceAnimum (talk | contribs)30,489 editsm trying this as per Gracenotes's suggestion← Previous edit Revision as of 17:07, 10 February 2008 view source Animum (talk | contribs)30,489 editsm index?Next edit →
Line 25: Line 25:
req.onreadystatechange = function() { req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) { if (req.readyState == 4 && req.status == 200) {
var user = req.responseXML.getElementsByTagName('user'); var user = req.responseXML.getElementsByTagName('user');
var count = user.getAttribute('editcount'); 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.")); if(user.getAttribute('missing') == undefined) /* The user exists, no? */ alert(user.getAttribute('name') + " has " + count + " surviving edit" + (count == 1 ? "." : "s."));

Revision as of 17:07, 10 February 2008

//<pre><nowiki>
importScript('User:Voice of All/Addtabs/monobook.js');

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