User:Markhurd/hidetopcontrib.js: Difference between revisions

Content deleted Content added
Markhurd (talk | contribs)
add missing code & whitespace; try catching mismatched regex differently
Add changes by User:Suffusion of Yellow: use the new mw-contributions-title to make things much easier (Discussed here)
 
(40 intermediate revisions by 6 users not shown)
Line 1:
// [[User:Ais523Markhurd/hidetopcontrib.js]]
// Based on [[User:Ais523/hidetopcontrib.js]]
// By a suggestion by [[User:Discospinster]]
// 090325 MEH Attempting to fixFixed 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">
// This script color-codes lines according to who has the top contribution for a page.
// Add userHideAllSubsequent user setting.
// Fix issue reported by [[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 [[Wikipedia:Added or removed characters|WP:AORC]] by removing support for top not using the mw-uctop class.
// 121123 User:Waldir Allow user configuration of link ___location and text.
// 150121 MEH Remove legacy Javascript.
// 170608 Fixed dependency declaration for mediawiki.util
// 180413 User:Amorymeltzer allow for compatibility with a couple other scripts present on contributions page
// 200107 User:Suffusion_of_Yellow use mw-contributions-title class instead of guessing which link is to the title
 
// 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=li.getElementsByTagName("li");
li = document.getElementById( "article" );
i=-1;
if ( li === null )
a=new Array();
li = document.getElementById( "mw_main" );
while(++i<li.length)
li = li.getElementsByTagName( "li" );
i = -1;
a = new Array();
while ( ++i < li.length )
{
var s,t,links;
tlinks = li[i].innerHTML.matchgetElementsByClassName(/ "\/wiki\/([^"]*)mw-contributions-title"/ );
 
if (t! typeof links == 'undefined' || links.length != 1 )
t=t[1]continue;
t = links[0].innerHTML;
if ( /* li[i].getElementsByTagName("strong").length>0|| */ li[i].innerHTML.match(/mw\-uctop/i) != undefined )
s = "none";
else
{ s = "";
t=li[i].innerHTML.match(/"\/w\/index\.php\?title\=([^&]*)\&amp\;redirect\=no"/);
if ( a[t] != undefined )
 
s = userHideAllSubsequent ? "none" : a[t];
if(t!=undefined)
t=t[1];
else
continue;
}
 
if(li[i].getElementsByTagName("strong").length>0)
s="none";
else
sa[t] ="" s;
 
if (a[t] s !=undefined "" )
// li[i].innerHTML=li[i].innerHTML + ":'" + s + "'";
s=a[t];
li[i].style.display = ( li[i].style.display == "none" ? "list-item" : "none" );
else
a[t]=s;
 
if(s!="")
{
 
// li[i].style.display=(li[i].style.display=="none"?"list-item":"none");
 
li[i].innerHTML=li[i].innerHTML + ":";
 
}
}
}
 
$.when( mw.loader.using('mediawiki.util'), $.ready).done( function() {
addOnloadHook(function () {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Contributions') {
if((___location.href.indexOf("Special:Contributions")!=-1||
var htPortletLink = mw.util.addPortletLink( portletId, '#', portletText, 'ca-hidetop',
___location.href.indexOf("Special%3AContributions")!=-1))
"Show/hide pages for which you're the top contributor", '' );
addPortletLink('p-cactions', 'javascript:hidetopcontrib()', 'show/hide top', 'ca-hidetop',
$( htPortletLink ).click( function ( e ) {
"Show/hide pages for which you're the top contributor", '');
e.preventDefault();
});
hidetopcontrib();
 
});
}
});
//</nowiki></pre>
//[[Category:Wikipedia scripts]]