User:Mr.Z-man/patrollinkstest.js

var showbydefault; 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 { var isSysop = false; for (var s in mw.config.get('wgUserGroups')) { if (mw.config.get('wgUserGroups')[s] == "sysop") { isSysop = true; } } 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) { stuff = document.createTextNode("Patrol"); openb = document.createTextNode(" ["); closeb = document.createTextNode("]"); 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"); plink.appendChild(stuff); plink.href = link; bracket = document.createElement("span"); bracket.id = "plink" + plinksindex ; bracket.appendChild(openb); bracket.appendChild(plink); bracket.appendChild(closeb); unpatrolled[plinksindex].appendChild(bracket); if (isSysop) { openb2 = document.createTextNode(" ["); closeb2 = document.createTextNode("]"); stuff2 = document.createTextNode("Delete"); link2 = mw.config.get('wgScript') +'?title=' + title + '&action=delete'; dlink = document.createElement("a"); dlink.setAttribute("style", "color:#C80815"); dlink.appendChild(stuff2); dlink.href = link2; bracket2 = document.createElement("span"); bracket2.id = "dlink" + plinksindex ; bracket2.appendChild(openb2); bracket2.appendChild(dlink); bracket2.appendChild(closeb2); unpatrolled[plinksindex].appendChild(bracket2); }   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"); }