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 script will place a button at the top of any NRHP county/state list that when clicked on will check and automatically fixthe ordering of the numbers in the first column of the NRHP table. If no reordering is needed, a null edit will be performed.This is useful when a property has been added to or removed from the list, causing all rows below it to be off by one.*/functionRenumberButton(){if((mw.config.get('wgPageName').search("National_Register_of_Historic_Places_listings_in")==-1&&mw.config.get('wgPageName').search("National_Historic_Landmarks_in")==-1)||mw.config.get('wgNamespaceNumber')!=0){return}if(___location.href.indexOf('action')!=-1||___location.href.indexOf('Talk:')!=-1)returnvarbutton=document.createElement("input")button.setAttribute("type","button");button.setAttribute("value","Renumber list");button.setAttribute("id","button");button.setAttribute("onclick","RenumberClick()");varcontent=document.getElementById('mw-content-text')content.parentNode.insertBefore(button,content)}functionRenumberClick(){varbutton=document.getElementById('button')button.value="Working..."button.disabled=truegetListWikitext(mw.config.get('wgPageName'))}functiongetListWikitext(title){$.getJSON(mw.util.wikiScript('api'),{format:'json',action:'query',prop:'revisions',rvprop:'content',titles:title,indexpageids:true}).done(function(data){varpage,wikitext;for(pageindata.query.pages){wikitext=data.query.pages[page].revisions[0]['*'];RenumberList(wikitext)}}).fail(function(){alert('Could not get wikitext; failure.');});}functionRenumberList(wikitext){varsplittext=wikitext.split("|}")varnewwikitext=''for(varj=0;j<splittext.length-1;j++){varStartIndex=0varstr="|pos="varskip=str.length;varindex,RowLocations=[];while((index=splittext[j].indexOf(str,StartIndex))>-1){RowLocations.push(index);StartIndex=index+skip;}varstop=RowLocations.length+1varcomments=splittext[j].match(/\<\!\-\-(.|[\r\n])*?\-\-\>/g)if(comments!=null){for(varl=0;l<comments.length;l++){if(comments[l].indexOf(str)==-1){comments.splice(l,1);l--}// remove comments that don't include a row}}vark=0for(vari=1;i<stop;i++){varStartIndex=RowLocations[i-1]+1if(comments!=null&&k<comments.length){if(StartIndex>splittext[j].indexOf(comments[k])&&StartIndex<splittext[j].indexOf(comments[k])+comments[k].length){k++continue;}}varstr="|"varNextParam=splittext[j].indexOf(str,StartIndex)varRowNum=i-ksplittext[j]=splittext[j].substr(0,StartIndex-1)+"|pos="+RowNum+splittext[j].substr(NextParam-1,splittext[j].length-NextParam+1)varStartIndex=0varstr="|pos="varskip=str.length;varindex,RowLocations=[];while((index=splittext[j].indexOf(str,StartIndex))>-1){RowLocations.push(index);StartIndex=index+skip;}}newwikitext+=splittext[j]+"|}"}newwikitext+=splittext[splittext.length-1]editNRHPPage({title:mw.config.get('wgPageName'),text:newwikitext,summary:'[[User:Dudemanfellabra/ReorderNRHPlist.js|Semi-automated]] renumbering of list items after addition/deletion.'});}functioneditNRHPPage(info){$.ajax({url:mw.util.wikiScript('api'),type:'POST',dataType:'json',async:false,data:{format:'json',action:'edit',title:info.title,text:info.text,summary:info.summary,token:mw.user.tokens.get('editToken')}}).done(function(data){if(data&&data.edit&&data.edit.result&&data.edit.result=='Success'){alert("Success! Rows renumbered!")}else{alert("Error! Rows not renumbered! Refresh the page to try again")}}).fail(function(){alert('Ajax failure.');});}$(RenumberButton);