User:Msh210/redlinks.js

//with thanks to Splarka for assistance // //Note that this runs an API query several times //(once per redlink on the page) if called by doit. // //Note also that it has not been tested, //was written by someone who doesn't know what //he's doing, probably doesn't work, //and may, for all I know, break something. redlinks=document.getElementsByClassName('new'); var deleted=new Array(redlinks.length); if (redlinks.length) { var li=document.createElement('li'); var a=documemnt.createElement('a'); li.appendChild(a); a.textContent='Show this page\'s deleted links.';//FF only? a.onclick='doit'; var mv=document.getElementById('ca-move'); mv.parentNode.insertBefore(li,mv); }; function doit { for (var i=0;i<redlinks.length;i++) { deleted.item(i)=0; attrs=redlinks.item(i).attributes; href=attrs.getNamedItem("href"); url=href.value; urlarray=url.split("="); url=urlarray[1]; urlarray=url.split("&"); pagename=urlarray[0]; //the preceding just gets the pagename from the href attr of the redlink's a tag apiurl='http://en.wiktionary.org/w/api.php?format=json&callback=cb'; apiurl+='&action=query&list=logevents&lelimit=1&leprop=title&letype=delete&letitle='; apiurl+=pagename; function cb(string) {if string.indexOf(pagename)>-1 {deleted.item(i)=1}}; mw.loader.load(apiurl); if deleted.item(i) { title=attrs.getNamedItem("title"); tooltip=title.value; redlinks.item(i).setAttribute("title","DELETED:"+tooltip) } } }; function parse(query,string,index) { if query.readyState==4 { if query.status==200 { if query.responseText.indexOf(string)>-1 { deleted.item(index)=1 } } } };