Jump to content

User:Persian Poet Gal/topcontrib.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.
// script adapted from [[User:Ais523/topcontrib.js]]
 
// This script color-codes lines according to who has the top contribution for a page.
//<pre><nowiki>
addOnloadHook(function () {
  if((location.href.indexOf("Special:Contributions")!=-1||
      location.href.indexOf("Special%3AContributions")!=-1)
     &&location.href.indexOf("&ais523")==-1&&location.href.indexOf("?ais523")==-1)
     // the ais523 in the line above is meant to be ais523, not your username; it's
     // to avoid a clash with a couple of other scripts I've written. Feel free to
     // expand it to avoid clashes with other contribs-manipulating scripts, though.
  {
    var i,li,a;
    li=document.getElementById("bodyContent");
    li=li.getElementsByTagName("li");
    i=-1;
    a=new Array();
    while(++i<li.length)
    {
      var s,t;
      var html = li[i].innerHTML;
      var match = html.match(/"\/wiki\/([^"]*)"/);
      if (!match)
        match = html.match(/"\/w\/index.php\?title=([^"]*)&amp;redirect=no"/);
      t = match[1];
      var spans = li[i].getElementsByTagName("span");
      var topspanfound = false;
      for (var j = 0; j < spans.length; j++)
      {
        if (spans[j].className == "mw-uctop")
        {
           topspanfound = true;
           break;
        }
      }
      s = topspanfound ? "#FFFFFF" : "#FFCCCC";
      if(a[t]!=undefined) s=(a[t]=="#FFFFFF"?"#FFFFFF":"#FFCCCC"); else a[t]=s;
      li[i].innerHTML="<SPAN STYLE='background-color:"+s+"'>"+li[i].innerHTML+"</SPAN>";
    }
  }
});

//</nowiki></pre>
//[[Category:Wikipedia scripts]]