Difference between revisions of "User:Markhurd/hidetopcontrib.js"

From Wikimedia Australia
Jump to navigation Jump to search
m (missed an en: reference)
(Update for en changes)
Line 11: Line 11:
 
// 100428 MEH Cater better for new pages.
 
// 100428 MEH Cater better for new pages.
 
// 100519 User:Ale_jrb Cater for Single-Revision Deletion, newly available to Admins.
 
// 100519 User:Ale_jrb Cater for Single-Revision Deletion, newly available to Admins.
+
// 110520 User:Waldir Better page check.
 +
// 120206 MEH Cater for IE renderer differences.
 +
// 120207 MEH Cater for all skins.
 +
// 120321 MEH Cater for [[en:Wikipedia:Added or removed characters|WP:AORC]] by removing support for top not using the mw-uctop class.
 +
 
 
// This script hides lines according to who has the top contribution for a page.
 
// This script hides lines according to who has the top contribution for a page.
 
// If userHideAllSubsequent=true, all subsequent contributions are hidden too, more like watchlists.
 
// If userHideAllSubsequent=true, all subsequent contributions are hidden too, more like watchlists.
Line 19: Line 23:
 
if (typeof userHideAllSubsequent=='undefined')
 
if (typeof userHideAllSubsequent=='undefined')
 
  userHideAllSubsequent=false;
 
  userHideAllSubsequent=false;
 +
if (typeof portletId=='undefined')
 +
portletId = 'p-cactions';
 +
if (typeof portletText=='undefined')
 +
portletText = 'show/hide top';
 
   
 
   
 
function hidetopcontrib()
 
function hidetopcontrib()
Line 24: Line 32:
 
   var i,li,a;
 
   var i,li,a;
 
   li=document.getElementById("bodyContent");
 
   li=document.getElementById("bodyContent");
 +
  if (li===null)
 +
    li=document.getElementById("article");
 +
  if (li===null)
 +
    li=document.getElementById("mw_main");
 
   li=li.getElementsByTagName("li");
 
   li=li.getElementsByTagName("li");
 
   i=-1;
 
   i=-1;
Line 33: Line 45:
 
   
 
   
 
     b = 2;
 
     b = 2;
     if(li[i].innerHTML.match(/<abbr +[^>]*class *= *"newpage"/)==undefined) b++;
+
     if(li[i].innerHTML.match(/<abbr +[^>]*class *= *(['"])?newpage\1/i)==undefined) b++;
     if(li[i].innerHTML.match(/class *= *"mw-revdelundel-link"/)!=undefined) b++;
+
     if(li[i].innerHTML.match(/class *= *(['"])?mw-revdelundel-link\1/i)!=undefined) b++;
 
   
 
   
 
     if (typeof links=='undefined' || links.length<(b+1))
 
     if (typeof links=='undefined' || links.length<(b+1))
Line 41: Line 53:
 
     t=links[b].innerHTML;
 
     t=links[b].innerHTML;
 
   
 
   
     if(li[i].getElementsByTagName("strong").length>0||li[i].innerHTML.match(/mw\-uctop/)!=undefined)
+
     if( /* li[i].getElementsByTagName("strong").length>0|| */ li[i].innerHTML.match(/mw\-uctop/i)!=undefined)
 
       s="none";
 
       s="none";
 
     else
 
     else
Line 59: Line 71:
 
addOnloadHook(function () {
 
addOnloadHook(function () {
 
   if(wgCanonicalSpecialPageName == 'Contributions')
 
   if(wgCanonicalSpecialPageName == 'Contributions')
     addPortletLink('p-cactions', 'javascript:hidetopcontrib()', 'show/hide top', 'ca-hidetop',
+
     addPortletLink(portletId, 'javascript:hidetopcontrib()', portletText, 'ca-hidetop',
 
                     "Show/hide pages for which you're the top contributor", '');
 
                     "Show/hide pages for which you're the top contributor", '');
 
  });
 
  });

Revision as of 01:25, 6 June 2014

//[[User:Markhurd/hidetopcontrib.js]]
// Based on [[en:User:Ais523/hidetopcontrib.js]]
// By a suggestion by [[en:User:Discospinster]]
// 090325 MEH Fixed where it is not hiding all (top)s, starting with redirects
//            and continuing after any regex mismatch.
// 090615 MEH Cater for new <span class="mw-uctop">
//            Add userHideAllSubsequent user setting.
//            Fix issue reported by [[en:User talk:Markhurd/hidetopcontrib.js#Bug|Lenore]].
// 100407 MEH Use simplified regex that works on IE8.
// 100413 MEH Cater for new pages.
// 100428 MEH Cater better for new pages.
// 100519 User:Ale_jrb Cater for Single-Revision Deletion, newly available to Admins.
// 110520 User:Waldir Better page check.
// 120206 MEH Cater for IE renderer differences.
// 120207 MEH Cater for all skins.
// 120321 MEH Cater for [[en:Wikipedia:Added or removed characters|WP:AORC]] by removing support for top not using the mw-uctop class.

// This script hides lines according to who has the top contribution for a page.
// If userHideAllSubsequent=true, all subsequent contributions are hidden too, more like watchlists.
 
//<pre><nowiki>
 
if (typeof userHideAllSubsequent=='undefined')
 userHideAllSubsequent=false;
if (typeof portletId=='undefined')
 portletId = 'p-cactions';
if (typeof portletText=='undefined')
 portletText = 'show/hide top';
 
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");
   }
 }
 
addOnloadHook(function () {
   if(wgCanonicalSpecialPageName == 'Contributions')
     addPortletLink(portletId, 'javascript:hidetopcontrib()', portletText, 'ca-hidetop',
                    "Show/hide pages for which you're the top contributor", '');
 });
 
//</nowiki></pre>
//[[Category:Wikipedia scripts]]