User:Huntster/adminrights.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//Administrator highlighter, shamelessly stolen from http://en.wikipedia.org/wiki/User:Ais523/adminrights.js
//Update this list at
//https://commons.wikimedia.org/w/index.php?title=Special:Listusers&limit=5000&group=sysop&huntsterupdate=y
var adminrights=new Array();
 
importScript('User:Huntster/adminrights-admins.js');
 
//Updating script
$(function(){
  if(location.href=="https://commons.wikimedia.org/w/index.php?title=Special:ListUsers&limit=5000&"+
                    "group=sysop&huntsterupdate=y")
  {
    var h=document.getElementById('bodyContent').innerHTML;
    var a=new Array();
    h=h.split(/\< *li *\>/i);
    var i=0;
    while(++i<h.length)
    {
      a[h[i].split(">")[1].split("<")[0]]=h[i].split(/\< *\/ *li *\>/i)[0];
    }
    for(i in a)
    {
      document.write("adminrights['"+
        encodeURIComponent(i).split("\\").join("\\\\").split("'").join("%27")
                             .split("(").join("%28").split(")").join("%29")
                             .split("%21").join("!").split("%2C").join(",")
                             .split("%3A").join(":")+"']=1;<BR/>");
    }
  }
});
 
//Highlighting script. Based on http://en.wikipedia.org/wiki/User:Ais523/highlightmyname.js
 
function highlightadmins(n,p) //node, parent node
{
  while(n!=null)
  {
    if(n.nodeType==1&&n.tagName.toLowerCase()=="a") //anchor
    {
      if(n.href.indexOf("https://commons.wikimedia.org/wiki/User:")!=-1)
      {
        var u=n.href.split("https://commons.wikimedia.org/wiki/User:")[1];
        if(adminrights[u.split("_").join("%20")]==1)
        {
          n.style.backgroundColor="#00FFFF";
          if(n.className==null||n.className=="") n.className="huntster_adminrights_admin";
          else n.className+="huntster_adminrights_admin";
        }
        n=n.nextSibling;
      }
      else if(n.href.indexOf("https://commons.wikimedia.org/wiki/User_talk:")!=-1)
      {
        var u=n.href.split("https://commons.wikimedia.org/wiki/User_talk:")[1];
        if(adminrights[u.split("_").join("%20")]==1)
        {
          n.style.backgroundColor="#00FFFF";
          if(n.className==null||n.className=="") n.className="huntster_adminrights_admin";
          else n.className+=" huntster_adminrights_admin";
        }
        n=n.nextSibling;
      }
      else if(n.href.indexOf("https://commons.wikimedia.org/wiki/Special:Contributions:")!=-1)
      {
        var u=n.href.split("https://commons.wikimedia.org/wiki/Special:Contributions:")[1];
        if(adminrights[u.split("_").join("%20")]==1)
        {
          n.style.backgroundColor="#00FFFF";
          if(n.className==null||n.className=="") n.className="huntster_adminrights_admin";
          else n.className+=" huntster_adminrights_admin";
        }
        n=n.nextSibling;
      }
      else if(n.href.indexOf("https://commons.wikimedia.org/w/index.php?title=User:")!=-1)
      {
        var u=n.href.split("https://commons.wikimedia.org/w/index.php?title=User:")[1];
        if(adminrights[u.split("_").join("%20")]==1)
        {
          n.style.backgroundColor="#00FFFF";
          if(n.className==null||n.className=="") n.className="huntster_adminrights_admin";
          else n.className+=" huntster_adminrights_admin";
        }
        n=n.nextSibling;
      }
      else if(n.href.indexOf("https://commons.wikimedia.org/w/index.php?title=User_talk:")!=-1)
      {
        var u=n.href.split("https://commons.wikimedia.org/w/index.php?title=User_talk:")[1];
        if(adminrights[u.split("_").join("%20")]==1)
        {
          n.style.backgroundColor="#00FFFF";
          if(n.className==null||n.className=="") n.className="huntster_adminrights_admin";
          else n.className+=" huntster_adminrights_admin";
        }
        n=n.nextSibling;
      }
      else
      {
        if(n.firstChild!=null) highlightadmins(n.firstChild,n);
        n=n.nextSibling;
      }
    }
    else
    {
      if(n.firstChild!=null) highlightadmins(n.firstChild,n);
      n=n.nextSibling;
    }
  }
}
 
$(function() {
  if(location.href.indexOf("?huntster")==-1&&location.href.indexOf("&huntster")==-1&&
     location.href.indexOf("?action=edit")==-1&&location.href.indexOf("?action=submit")==-1&&
     location.href.indexOf("&action=edit")==-1&&location.href.indexOf("&action=submit")==-1&&
     mw.config.get('wgPageName')!="Special:Preferences")
  {
    highlightadmins(document.getElementById('bodyContent').firstChild,
                    document.getElementById('bodyContent'));
  }
});