User:Markhurd/hidetopcontrib.js: Difference between revisions

Content deleted Content added
allow user configuration of link ___location and text (backwards-compatible)
Add changes by User:Suffusion of Yellow: use the new mw-contributions-title to make things much easier (Discussed here)
 
(6 intermediate revisions by 3 users not shown)
Line 15:
// 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.
Line 21 ⟶ 26:
//<pre><nowiki>
if ( typeof userHideAllSubsequent == 'undefined' )
userHideAllSubsequent = false;
if ( typeof portletId == 'undefined' )
portletId = 'p-cactions';
if ( typeof portletText == 'undefined' )
portletText = 'show/hide top';
Line 31 ⟶ 36:
{
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].getElementsByTagNamegetElementsByClassName( "amw-contributions-title" );
if ( typeof links == 'undefined' || links.length<(b+ != 1) )
s="none"continue;
bt = 2links[0].innerHTML;
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 ( /* li[i].getElementsByTagName("strong").length>0|| */ li[i].innerHTML.match(/mw\-uctop/i) != undefined )
if (typeof links=='undefined' || links.length<(b+1))
s = continue"none";
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" );
}
}
$.when( mw.loader.using('mediawiki.util'), $.ready).done( function() {
addOnloadHook(function () {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Contributions') {
var htPortletLink = mw.util.addPortletLink( portletId, 'javascript:hidetopcontrib()#', portletText, 'ca-hidetop',
"Show/hide pages for which you're the top contributor", '' );
$( htPortletLink ).click( function ( e ) {
});
e.preventDefault();
hidetopcontrib();
});
}
});
//</nowiki></pre>