Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//This function adds a link to the toolbox which, when clicked on a Category page, prompts for the name of a template,//checks if the pages listed contain that template, and changes the bullet to a tick mark if so.//To use this function add <nowiki>{{subst:js|User:Dr pda/templatecheck.js}}</nowiki> to your monobook.js//functionloadXMLDocPassingTemplateAndURL(url,handler,template){// branch for native XMLHttpRequest objectif(window.XMLHttpRequest){varreq=newXMLHttpRequest();}// branch for IE/Windows ActiveX versionelseif(window.ActiveXObject){varreq=newActiveXObject("Microsoft.XMLHTTP");}if(req){req.onreadystatechange=function(){handler(req,template,url)};req.open("GET",url,true);req.send("");}}functiongetTemplateList(req,template,url){// only if req shows "loaded"if(req.readyState==4){// only if "OK"if(req.status==200){// ...processing statements go here...varresponse=req.responseXML.documentElement;varpages=response.getElementsByTagName('page');if(pages.length>0){for(vari=0;i<pages.length;i++){vartl=pages[i].getElementsByTagName('tl');if(tl.length>0){for(varj=0;j<tl.length;j++){if(tl[j].getAttribute('title')==template){pagesList[pages[i].getAttribute('title')]='true';}}}}//Check for more pagesvartlcontinue='';varquerycontinue=response.getElementsByTagName('query-continue');if(querycontinue.length>0){varqctemplates=querycontinue[0].getElementsByTagName('templates');if(qctemplates.length>0){vartlcontinue=qctemplates[0].getAttribute('tlcontinue');loadXMLDocPassingTemplateAndURL(url+'&tlcontinue='+tlcontinue,getTemplateList,template);}}//Do processing once all tlcontinues have been followed if(tlcontinue==''){if(!list){mwPagesDiv=document.getElementById('mw-pages');liList=mwPagesDiv.getElementsByTagName('li');}if(liList.length>0){for(vari=0;i<liList.length;i++){varpageName=liList[i].firstChild.title;if(pagesList[pageName]){liList[i].style.cssText="list-style-image:url('http://upload.wikimedia.org/wikipedia/commons/thumb/5/52/%E2%98%91.svg/11px-%E2%98%91.svg.png')";}else{liList[i].style.cssText='';}}}varcheck=document.getElementById('t-check-template');if(check)removeSpinner('check');}}}else{alert("There was a problem retrieving the XML data:\n"+req.statusText);}}}functioncheckTemplates(){vartemplate=prompt("Enter the template you want to check for\n (Don't include Template:)","");varcheck=document.getElementById('t-check-template');if(check)injectSpinner(check,'check');template="Template:"+template.toUpperCase().substr(0,1)+template.substr(1);pagesList=newObject();if(list){listNumber=prompt("Enter the number of the section you want to check for "+template+"\n(See table of contents)");listNumber--;//array starts at 0varolList=document.getElementsByTagName('ol');if(!(olList.length>0&&olList[listNumber])){alert("Error. There are only"+olList.length+" lists on this page");return0;}liList=olList[listNumber].getElementsByTagName('li');vartitleString1='';vartitleString2='';for(vari=0;i<50;i++){titleString1+=encodeURIComponent(liList[i].firstChild.title+'|');titleString2+=encodeURIComponent(liList[i+50].firstChild.title+'|');}titleString1=titleString1.substring(0,titleString1.length-1);titleString2=titleString2.substring(0,titleString2.length-1);queryURL1='/w/api.php?action=query&titles='+titleString1+'&tllimit=500&prop=templates&format=xml';queryURL2='/w/api.php?action=query&titles='+titleString2+'&tllimit=500&prop=templates&format=xml';loadXMLDocPassingTemplateAndURL(queryURL1,getTemplateList,template);loadXMLDocPassingTemplateAndURL(queryURL2,getTemplateList,template);}else{queryURL='/w/api.php?action=query&generator=categorymembers&gcmtitle='+mw.config.get('wgPageName')+'&gcmlimit=200&prop=templates&tllimit=500&format=xml';loadXMLDocPassingTemplateAndURL(queryURL,getTemplateList,template);}}addOnloadHook(function(){if(mw.config.get('wgCanonicalNamespace')=='Category'){list=false;mw.util.addPortletLink('p-tb','javascript:checkTemplates()','Check for template','t-check-template','Check pages in category for use of a template','','');}elseif(document.___location.href.indexOf('List_of_biographies/')!=-1){list=true;mw.util.addPortletLink('p-tb','javascript:checkTemplates()','Check for template','t-check-template','Check pages in list for use of a template','','');}});