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 adds a "Select all nonexistent pages" button to the watchlist edit page([[Special:Watchlist/edit]]). To install it, add the line: importScript('User:Ilmari_Karonen/unwatchredlinks.js');to your monobook.js page (or to the corresponding page for other skins).The button will only select pages that do not exist and do not have existing talkpages either. As an unintended -- but probably desirable -- side effect, it willnot select user pages of any existing users either.*/if(mw.config.get('wgCanonicalNamespace')=="Special"&&mw.config.get('wgCanonicalSpecialPageName')=="Watchlist"){addOnloadHook(function(){// It's somewhat hard to tell if we're on the "edit watchlist" subpage,// so we'll just proceed as if we were and abort if something looks odd.varform=document.getElementsByTagName("form")[0];if(!form)return;// This is our main check for which page we're on:if(!/[&?]action=edit(&|$)/.test(form.action))return;varinputs=form.getElementsByTagName("input");if(!inputs||inputs.length<1)return;varsubmit=inputs[inputs.length-1];if(submit.type!="submit")return;inputs=null;// Okay so far, now add the custom button.varbutton=document.createElement("input");button.type="button";button.value="Select all nonexistent pages";button.onclick=function(){// Here's the code for what happens when you click it. varitems=form.getElementsByTagName("li");if(!items||items.length<1)return;for(vari=0;i<items.length;i++){varinput=items[i].getElementsByTagName("input")[0];if(!input||input.getAttribute("type")!="checkbox")continue;varisRedlink=true;// assume redlink until proven otherwisevarlinks=items[i].getElementsByTagName("a");for(varj=0;isRedlink&&j<links.length;j++){isRedlink=/[&?]action=edit(&|$)/.test(links[j].href);}input.checked=isRedlink;}};// Now add the button to the page.if(submit.nextSibling)submit.parentNode.insertBefore(button,submit.nextSibling);elsesubmit.parentNode.appendChild(button);// Looks nicer with a space...button.parentNode.insertBefore(document.createTextNode(" "),button);});}