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.
/* Random Dab Finder, version [0.0.0]Originally from: http://en.wikipedia.org/wiki/User:Splarka/randab.jsBased on http://en.wikibooks.org/w/index.php?title=MediaWiki:Common.js/RandomBook.js&oldid=1496500Grabs 10 random pages from the API, checks if any are disambiguations. Repeats until it finds a match.Notes:* Don't grab more than 10 random pages. Logged in users can get more, but anon users cannot. ** Since this uses callback, all users are limited to 10 anyway.* Automatically re-queries until it finds a page in "Category:All disambiguation pages".** As 5.4% of pages are in this category, most queries should take only 2 or 3 iterations.* Setting window.location.href eats history in some browsers.** To show a link instead use: var ranDabAsLink = true; (users can set this in their monobook individually too).* Uses curid links, I usually trust these more than trying to generate /wiki links.*/varranDabAsLink=false;varrbrqid=0;varrburl=mw.config.get('wgServer')+mw.config.get('wgScriptPath')+'/api.php?action=query&indexpageids=1&generator=random&grnnamespace=0&grnlimit=10&prop=categories&cllimit=max&format=json&callback=showRanDabCB&requestid=rb';functionshowRanDab(){injectSpinner(document.getElementById('n-randab').firstChild,'ranDabSpinner');mw.loader.load(rburl+rbrqid);rbrqid++;}functionshowRanDabCB(obj){if(!obj['query']||!obj['query']['pages']||!obj['query']['pageids']){document.getElementById('n-randab').appendChild(document.createTextNode(' error'));removeSpinner('ranDabSpinner');returnfalse;}varid=obj['query']['pageids'];varfound;for(vari=0;i<id.length;i++){varcats=obj['query']['pages'][id[i]]['categories'];if(!cats)continuefor(varj=0;j<cats.length;j++){varct=cats[j]['title'];if(ct=='Category:All disambiguation pages'){found=obj['query']['pages'][id[i]];break;}}if(found)break}if(!found){// didn't find any, try againmw.loader.load(rburl+rbrqid);rbrqid++;}else{removeSpinner('ranDabSpinner');varlink=mw.config.get('wgServer')+mw.config.get('wgScript')+'?curid='+found['pageid'];if(window.ranDabAsLink){vara=document.createElement('a');a.setAttribute('href',link);a.style.display='block';a.appendChild(document.createTextNode(' \u2022\u00A0'+found['title']))document.getElementById('n-randab').appendChild(a);}elseif(window.location.assign){window.location.assign(link);}else{window.location.href=link;}}returntrue;}functionshowRanDabLink(){mw.util.addPortletLink('p-navigation','javascript:showRanDab();','Random dab','n-randab','Show me a random disambiguation page');}$(showRanDabLink);