Jump to content

User:Lupin/nichalp links.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.
// culled from [[User:Lupin/popups.js]]

function nichalp_articleFromURL(h) {
  if (typeof h != 'String') h=String(h);
  h=decodeURI(h);
  var m=RegExp('[^:]*://en\\.wikipedia\\.org/(wiki/|w/index\\.php\\?title=)([^&?]*)').exec(h);
  if(m===null) return null;
  return m[2];
}

function nichalp_isIpUser(user) {
  return RegExp('(User:)?' + 
                '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}' + 
                '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])')
    .test(user);
}

function nichalp_removeAnchor(article) {
  // is there a #? if not, we're done
  var i=article.indexOf('#');
  if (i == -1) return article;
  return article.substring(0,i);
}

function nichalp_userName(article) {
  var i=article.indexOf('User');
  var j=article.indexOf(':');
  if  (i != 0 || j == -1) return null;
  var k=article.indexOf('/');
  if (k==-1) return article.substring(j+1);
  else return article.substring(j+1,k);
}

// do it

function nichalp_customLinks() {
  addPurge();
  var article=nichalp_articleFromURL(document.location.href);
  if (!article) return;
  var user=nichalp_userName(article);
  if(!user) return;
  user=nichalp_removeAnchor(user);
  if (!nichalp_isIpUser(user)) {
    addToolboxLink('http://kohl.wikimedia.org/~kate/cgi-bin/count_edits?dbname=enwiki&user='+user, user+"'s edit count", 'toolbox_katestool');
  }
  var special='http://en.wikipedia.org/w/index.php?title=Special:';
  addToolboxLink(special + 'Contributions/' + user, user+"'s contribs", 'toolbox_usercontribs');
  addToolboxLink(special + 'Log&user='+user, user+"'s log", 'toolbox_userlog');
  addToolboxLink(special + 'Blockip&ip='+user, 'Block '+user, 'toolbox_blockuser'); 
  addToolboxLink(special + 'Special:Ipblocklist&action=unblock&ip='+user, 'Unblock '+user, 'toolbox_unblockuser'); 
}

// make it all happen on page load

addOnloadHook(nichalp_customLinks);