v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "User:Emi/colorcontrib.js"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(addOnloadHook -> $)
 
Line 3: Line 3:
 
// This script color-codes lines according to who has the top contribution for a page.
 
// This script color-codes lines according to who has the top contribution for a page.
 
//<pre><nowiki>
 
//<pre><nowiki>
addOnloadHook(function () {
+
$(function () {
 
   if((location.href.indexOf("Special:Contributions")!=-1||
 
   if((location.href.indexOf("Special:Contributions")!=-1||
 
       location.href.indexOf("Special%3AContributions")!=-1)
 
       location.href.indexOf("Special%3AContributions")!=-1)

Latest revision as of 00:50, 10 June 2019

// [http://en.wikipedia.org/wiki/User:Ais523/topcontrib.js]

// This script color-codes lines according to who has the top contribution for a page.
//<pre><nowiki>
$(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(/"\/index.php\/([^"]*)"/);
      if (!match)
        match = html.match(/"\/index.php\?title=([^"]*)&amp;redirect=no"/);
      t = match[1];
      var spans = li[i].getElementsByTagName("strong");
      var topspanfound = false;
      for (var j = 0; j < spans.length; j++)
      {
        if (spans[j].innerHTML == "(top)")
        {
           topspanfound = true;
           break;
        }
      }
      s = topspanfound ? "#CCCCFF" : "#FFCCCC";
      if(a[t]!=undefined) s=(a[t]=="#CCCCFF"?"#CCFFFF":"#FFFFCC"); else a[t]=s;
      li[i].innerHTML="<SPAN STYLE='background-color:"+s+"'>"+li[i].innerHTML+"</SPAN>";
    }
  }
});

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