User:Armbrust/hidetopcontrib.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
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.
if (typeof userHideAllSubsequent=='undefined')
 userHideAllSubsequent=false;
 
function hidetopcontrib()
{
   var i,li,a;
   li=document.getElementById("bodyContent");
   if (li===null)
     li=document.getElementById("article");
   if (li===null)
     li=document.getElementById("mw_main");
   li=li.getElementsByTagName("li");
   i=-1;
   a=new Array();
   while(++i<li.length)
   {
     var s,t,links,b;
     links=li[i].getElementsByTagName("a");
 
     b = 2;
     if(li[i].innerHTML.match(/<abbr +[^>]*class *= *(['"])?newpage\1/i)==undefined) b++;
     if(li[i].innerHTML.match(/class *= *(['"])?mw-revdelundel-link\1/i)!=undefined) b++;
 
     if (typeof links=='undefined' || links.length<(b+1))
           continue;
 
     t=links[b].innerHTML;
 
     if( /* li[i].getElementsByTagName("strong").length>0|| */ li[i].innerHTML.match(/mw\-uctop/i)!=undefined)
       s="none";
     else
       s="";
 
     if(a[t]!=undefined)
       s=userHideAllSubsequent?"none":a[t];
     else
       a[t]=s;
 
     if(s!="")
       // li[i].innerHTML=li[i].innerHTML + ":'" + s + "'";
       li[i].style.display=(li[i].style.display=="none"?"list-item":"none");
   }
 }
 
$(function () {
   if(mw.config.get('wgCanonicalSpecialPageName') == 'Contributions')
     mw.util.addPortletLink('p-cactions', 'javascript:hidetopcontrib()', 'show/hide top', 'ca-hidetop',
                    "Show/hide pages for which you're the top contributor", '');
 });