User:MordantMaenad/scripts/markpatrolled.js

function qbonc(stuff, rcid, title, func, i, rlinks, arr) { stuff.onclick = function { func(rcid, title); for (var ab in arr) { if (arr[ab].className == "unpatrolled") rlinks[i].parentNode.removeChild(arr[ab]); }   var spans = rlinks[i].parentNode.getElementsByTagName('span'); for (var s in spans) { if (spans[s].className == "mark-as-patrolled-link") rlinks[i].parentNode.removeChild(spans[s]); } } }

function markpatrolled(rcid, title) { var req = sajax_init_object; req.open('GET', wgServer + wgScriptPath + '/index.php?title=' + title + '&action=markpatrolled&rcid=' + rcid, true); req.send(null); }

function markpat { var reflinks = getElementsByClassName(document.getElementById('bodyContent'),"*","mw-usertoollinks"); var unpatsar = new Array; for (var j = 0; j < reflinks.length; j++) { var lef = reflinks[j].parentNode.getElementsByTagName('abbr'); if (lef.length != 0) { var lefclasses = new Array; for (var n = 0; n < lef.length; n++) { lefclasses.push(lef[n].className); }     if (lefclasses.toString.search("unpatrolled") != -1) { var markspan = document.createElement('span'); markspan.className = "mark-as-patrolled-link"; var marklink = document.createElement('a'); marklink.innerHTML = "mark as patrolled"; var anchs = reflinks[j].parentNode.getElementsByTagName('a'); if (lefclasses[0] == "newpage") { var rcid = anchs[1].href.slice(anchs[1].href.length-6); var artName = escape(anchs[1].innerHTML); } else { var rcid = anchs[0].href.slice(anchs[0].href.length-6); var artName = escape(anchs[2].innerHTML); }       //marklink.href = wgServer + wgScript + "?&title=" + artName + "&action=markpatrolled&rcid=" + rcid; qbonc(marklink, rcid, artName, markpatrolled, j, reflinks, lef); marklink.style.cursor = "pointer"; markspan.appendChild(document.createTextNode(" [")); markspan.appendChild(marklink); markspan.appendChild(document.createTextNode("]")); reflinks[j].parentNode.appendChild(markspan); }   }  } }

addOnloadHook(markpat);