Jump to content

User:Splarka/sysopdectector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MZMcBride (talk | contribs) at 07:40, 8 December 2008 (no need for a version bump...). 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.
/* Sysop decrier/detector (rights group displayer), version [0.1.3]
Originally from http://en.wikipedia.org/wiki/User:Splarka/sysopdectector.js

Notes:
* Fixed this up to use the new API fun stuffs.
* Shows all groups now
* nstab-user isn't available in all skins, all skins have at least one h1 or h2 I believe.
* heading given class="detected-userrights-heading" and text in span class="detected-userrights"
*/

if((wgNamespaceNumber == 2 || wgNamespaceNumber == 3) && wgTitle.indexOf('/') == -1 && (wgAction != 'edit' || wgAction != 'submit')) addOnloadHook(showUserGroups)
function showUserGroups() {
  var url = wgServer + wgScriptPath + '/api.php?action=query&format=json&callback=showUserGroupsCB&maxage=86400&smaxage=86400&usprop=blockinfo|groups|editcount|registration&list=users&ususers=' + encodeURIComponent(wgTitle);
  importScriptURI(url);
}

function showUserGroupsCB(obj) {
  if(!obj['query'] || !obj['query']['users']) return
  var user = obj['query']['users'];
  if(user.length == 0) return
  user = user[0];
  var someHeading = document.getElementsByTagName('h1')[0] || document.getElementsByTagName('h2')[0]
  if(!someHeading) return

  var span = document.createElement('span');
  var title = '[' + user['name'] + '] ';
  var text = '';

  if(user['invalid'] == '') title += 'invalid or reserved (IP) username'
  if(user['missing'] == '') text +=' [no such user]'
  if(user['editcount']) title += 'Edits: ' + user['editcount'] + '; '
  if(user['registration']) title += 'Created: ' + user['registration'] + '; '
  if(user['groups']) text += ' [' + user['groups'] + ']'
  if(user['blockedby']) text += ' [currently blocked]'

  span.setAttribute('class','detected-userrights');
  span.appendChild(document.createTextNode(text));
  someHeading.appendChild(span);
  someHeading.setAttribute('title',title);
  someHeading.className += ' detected-userrights-heading';
}