User:Slakr/patrolLinks.js

// Copied from User:Mr.Z-man/patrollinks.js var showbydefault = true; var plinksindex = 0; function patrollinks { if (mw.config.get('wgPageName') == "Special:NewPages" ) { mw.util.addPortletLink('p-cactions', 'javascript:patrollinksclick', "patrol links", "ca-plinks-show1", "Add patrol links to this page"); if (!document.getElementById('p-cactions') || showbydefault) { addOnloadHook(patrollinksclick); }   if (showbydefault) { document.getElementById('ca-plinks-show1').style.display = 'none'; } } } $(patrollinks); function patrollinksclick { if (document.getElementById('p-cactions')) { mw.util.addPortletLink('p-cactions', 'javascript:patrollinkshide', "hide patrol links", "ca-plinks-hide", "Hide patrol links"); document.getElementById('ca-plinks-show1').style.display = 'none'; } unpatrolled = getElementsByClassName(document, "li", "not-patrolled"); while(plinksindex < unpatrolled.length) { code = unpatrolled[plinksindex].getElementsByTagName('a')[0].href.toString rcid = code.substring(code.indexOf('rcid=')+5); title = code.substring(code.indexOf('title=')+6, code.indexOf('&rcid=')); link = mw.config.get('wgScript')+ '?title=' + title + '&action=markpatrolled&rcid=' + rcid; plink = document.createElement("a"); stuff = document.createTextNode("Patrol"); plink.appendChild(stuff); plink.href = link; openb = document.createTextNode(" ["); closeb = document.createTextNode("]"); bracket = document.createElement("span"); bracket.id = "plink" + plinksindex ; bracket.appendChild(openb); bracket.appendChild(plink); bracket.appendChild(closeb); unpatrolled[plinksindex].appendChild(bracket); plinksindex++ } } function patrollinkshide { var j for (j = 0; j<plinksindex ; j++) {   document.getElementById('plink'+j).style.display = 'none'; } document.getElementById('ca-plinks-hide').style.display = 'none'; mw.util.addPortletLink('p-cactions', 'javascript:patrollinksshowagain', "patrol links", "ca-plinks-show", "Add patrol links to unpatrolled entries"); } function patrollinksshowagain { var j for (j = 0; j<plinksindex ; j++) {   document.getElementById('plink'+j).style.display = ''; } document.getElementById('ca-plinks-show').style.display = 'none'; mw.util.addPortletLink('p-cactions', 'javascript:patrollinkshide', "hide patrol links", "ca-plinks-hide", "Hide patrol links"); }