User:Dr pda/strikethrough.js

//This function adds a link to the toolbox which, when clicked on a subpage of //WikiProject Persondata/List of biographies, strikes through all those articles //which transclude the template //To use this function add User:Dr pda/strikethrough.js to your monobook.js // function loadXMLDocPassingTemplateAndURL(url,handler,template) {    // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { var req = new XMLHttpRequest; }    // branch for IE/Windows ActiveX version else if (window.ActiveXObject) { var req = new ActiveXObject("Microsoft.XMLHTTP"); }   if (req) { req.onreadystatechange = function {handler(req,template,url)}; req.open("GET", url, true); req.send(""); } } function getStrikethroughTemplateList(req,template,url) { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { // ...processing statements go here... var response = req.responseXML.documentElement; var pages = response.getElementsByTagName('page'); if(pages.length > 0){ for(var i=0;i 0){ for(var j=0;j0){ var qctemplates = querycontinue[0].getElementsByTagName('templates'); if(qctemplates.length>0){ var tlcontinue = qctemplates[0].getAttribute('tlcontinue'); jobsLeft++; loadXMLDocPassingTemplateAndURL(url+'&tlcontinue='+tlcontinue,getStrikethroughTemplateList,template); }           }               //Do processing once all tlcontinues have been followed if(tlcontinue=='' && jobsLeft==0){ for(x in list){ var match = list[x].match(/# \[\[(.*)\]\]/); if(match && match.length==2){ var pageName = match[1]; if(pagesList[pageName]){ list[x] = "# " + pageName + " "; }                }              }              document.getElementById('wpTextbox1').value = list.join('\n'); var check = document.getElementById('t-strike-persondata'); if(check) removeSpinner('check'); }         }         } else { alert("There was a problem retrieving the XML data:\n" +                req.statusText); }    } }  function strikePersondata{ var template=prompt("Enter the template you want to check for\n (Don't include Template:)",""); var check = document.getElementById('t-strike-persondata'); if(check) injectSpinner(check,'check'); template = "Template:"+template.toUpperCase.substr(0,1)+template.substr(1); pagesList = new Object; text = document.getElementById('wpTextbox1').value; list = text.split('\n'); var titleString = ''; jobsLeft = 0; queryURL = '/w/api.php?action=query&tllimit=500&prop=templates&format=xml&titles='; for(i in list){ var match = list[i].match(/# \[\[(.*)\]\]/); if(match && match.length==2){ //API limited to 50 titles per query if( i%50 == 0 && i>0){ titleString = titleString.substr(1); jobsLeft++; loadXMLDocPassingTemplateAndURL(queryURL+titleString,getStrikethroughTemplateList,template); titleString=''; }     titleString += '|' + encodeURIComponent(match[1]); } }  //Process remainder titleString = titleString.substr(1); jobsLeft++; loadXMLDocPassingTemplateAndURL(queryURL+titleString,getStrikethroughTemplateList,template); } addOnloadHook(function  {   if(document.location.href.indexOf('List_of_biographies/') != -1){     mw.util.addPortletLink('p-tb', 'javascript:strikePersondata', 'Strike items with persondata', 't-strike-persondata', 'Strikethrough pages in list which already have persondata', , );   } });