User:Markhurd/hidetopcontrib.js: Difference between revisions

Content deleted Content added
// 100705 User:Ale_jrb Adds "hideTop" variable to move the button lower when false
Add changes by User:Suffusion of Yellow: use the new mw-contributions-title to make things much easier (Discussed here)
 
(16 intermediate revisions by 5 users not shown)
Line 11:
// 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.
// 100705 User:Ale_jrb Adds "hideTop" variable to move the button lower when false
// 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.
// If userHideTop=false, the button moves from the top bar to after the (20 | 50 | 100 | 250 | 500) marker
//<pre><nowiki>
if ( typeof userHideAllSubsequent === 'undefined' )
userHideAllSubsequent = false;
if ( typeof userHideTopportletId === 'undefined' ) userHideTop = true;
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,b;
links = li[i].getElementsByTagNamegetElementsByClassName( "amw-contributions-title" );
if ( typeof links == 'undefined' || links.length<(b+ != 1) )
b = 2;
continue;
if(li[i].innerHTML.match(/<abbr +[^>]*class *= *"newpage"/)==undefined) b++;
if(li[i].innerHTML.match(/class *= *"mw-revdelundel-link"/)!=undefined) b++;
if (typeof links=='undefined' || links.length<(b+1))
continue;
t = links[b0].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' ) {
if ( userHideTop === true ) {
var htPortletLink = mw.util.addPortletLink( portletId, '#', portletText, 'ca-hidetop',
if ( wgCanonicalSpecialPageName === 'Contributions' ) {
"Show/hide pages for which you're the top contributor", '' );
var button = document.createElement ( 'span' );
$( htPortletLink ).click( function ( e ) {
button.id = 'hidetop-button';
e.preventDefault();
button.innerHTML = '&nbsp;(<a href="#" onclick="hidetopcontrib (); this.innerHTML = ( this.innerHTML == \'hide top contribs\' ? \'show top contribs\' : \'hide top contribs\' ); return false;">hide top contribs</a>)';
hidetopcontrib();
b = 2});
document.getElementById('bodyContent').childNodes[10].appendChild ( button );
}
}
});
} else {
if((___location.href.indexOf("Special:Contributions")!=-1 ||
___location.href.indexOf("Special%3AContributions")!=-1))
addPortletLink('p-cactions', 'javascript:hidetopcontrib()', 'show/hide top', 'ca-hidetop',
"Show/hide pages for which you're the top contributor", '');
}
});
//</nowiki></pre>