User:Jmcgnh/hidetopcontribs.js

/* Contributions (top) edit hider, version [0.0.4] Originally from http://en.wikipedia.org/wiki/User:Splarka/hidetopcontribs.js Repairs by user jmcgnh 2017-10-22

On Special:Contributions page, add button to hide all pages the current user is top contributor on

Notes:
 * If on an offset or dir URI, one cannot reliably determine top edits, so it isn't active.


 * When I use this, I am also uninterested in seeing my own earlier contributions, so we only want to display the latest of my own contribs



// This first stanza checks to see if the current page is a Special Contributions page and adds a button hooking into this script if(mw.config.get('wgCanonicalSpecialPageName') && mw.config.get('wgCanonicalSpecialPageName') == 'Contributions' && !queryString('offset') && !queryString('dir')) addOnloadHook(hideTopContribsButton);

function hideTopContribsButton { mw.util.addPortletLink('p-tb','javascript:hideTopContribs','Hide tops','tb-top','Hide all links to pages which this user is the last editor of'); }

function hideTopContribs { var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.body; var titles = []; var ul = docobj.getElementsByTagName('ul')[0]; // pick first list (checked that this is the right index) var tops = ul.getElementsByClassName('mw-uctop'); // this mw-uctop class name is present when the entry is marked "(current)" to say that this user is the most recent contributor for(var i=0;i link in the entry titles.push(titlelink); // keep track of titles of entries flagged with mw-uctop // console.log("pushing title=", titlelink); }

var li = ul.getElementsByTagName('li'); for( i=0;i<li.length;i++) { var lititle = li[i].getElementsByTagName('a')[0].title; var seen = 0; for(var j=0;j<titles.length;j++) { if(lititle == titles[j]) { li[i].style.display = 'none'; seen = 1; }   }    if( ! seen ) { titles.push(lititle); // console.log("pushing li title=", lititle); } } }

function queryString(p) { // I think this works because I can see the buttton appearing var re = RegExp('[&?#]' + p + '=([^&#]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }  return null; }