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.
//<pre>// Travel to a random page linked in the article (a so-called "aleation" or an "aleatory fugue")//// To use this script, add "importScript('User:Proteins/followrandomlinkonpage.js');" to your monobook.js subpage // under your user page, as you can see at User:Proteins/monobook.jsfunctionfollowRandomLinkOnPage(){varalert_string="";vartop_node;varhyperlinks;varnum_hyperlinks=0;varrandom_double=0.5;varrandom_hyperlink_index=0;varrandom_link;varrandom_link_href="";varrandom_link_title="";varnum_iterations=0;varmax_num_iterations=100;varbad_link=true;// Get the bodyContent nodetop_node=document.getElementById('bodyContent');if(!top_node){window.alert("There is no bodyContent node in this article.");return;}// Get a list of the hyperlinks hyperlinks=top_node.getElementsByTagName("A");if(!hyperlinks){window.alert("There are no hyperlinks in this article.");return;}num_hyperlinks=hyperlinks.length;if(num_hyperlinks<1){window.alert("There are no hyperlinks in this article.");return;}// Choose a random hyperlink bad_link=true;num_iterations=0;random_link=null;random_link_href="";random_link_title="";while((num_iterations<max_num_iterations)&&(bad_link)){num_iterations++;random_double=num_hyperlinks*Math.random();random_hyperlink_index=Math.floor(random_double);if((random_hyperlink_index<0)||(random_hyperlink_index>=num_hyperlinks)){continue;}random_link=hyperlinks[random_hyperlink_index];random_link_href=random_link.href;random_link_title=random_link.title;if((!random_link)||(!random_link_title)||(!random_link_title)){// Check that all three existcontinue;}elseif(random_link.className){// Don't follow external linkscontinue;}elseif(random_link_title.match(/\(page does not exist\)$/ig)){// Don't follow red linkscontinue;}elseif(random_link_title.match(/^Image:/ig)){// Don't follow Image linkscontinue;}elseif(random_link_title.match(/^Category:/ig)){// Don't follow Category linkscontinue;}elseif(random_link_title.match(/^Special:/ig)){// Don't follow links to Special pagescontinue;}elseif((random_link_title.match(/^Edit\ssection:/i))&&(random_link_href.match(/action\=edit/i))){// Don't follow edit linkscontinue;}if(wgNamespaceNumber==0){// special behavior for Main article spaceif(random_link.id){continue;}if(random_link_href.match(/Talk:/ig)){continue;}if(random_link_href.match(/Wikipedia:/ig)){continue;}if(random_link_href.match(/Wikipedia talk:/ig)){continue;}if(random_link_href.match(/Portal:/ig)){continue;}if(random_link_href.match(/Portal talk:/ig)){continue;}if(random_link_href.match(/User:/ig)){continue;}if(random_link_href.match(/User talk:/ig)){continue;}if(random_link_href.match(/Help:/ig)){continue;}if(random_link_href.match(/Help talk:/ig)){continue;}if(random_link_href.match(/Template:/ig)){continue;}if(random_link_href.match(/Template talk:/ig)){continue;}if(random_link_href.match(/Category:/ig)){continue;}if(random_link_href.match(/Category talk:/ig)){continue;}if(random_link_href.match(/File:/ig)){continue;}if(random_link_href.match(/File talk:/ig)){continue;}if(random_link_href.match(/MediaWiki:/ig)){continue;}if(random_link_href.match(/MediaWiki talk:/ig)){continue;}}// closes check for Main article spacebad_link=false;}// closes loop generating a random hyperlink// Follow the randomly chosen link to the new locationif(bad_link==false){alert_string="Follow link to the page \""+random_link_title+"\"\?\n";if(window.confirm(alert_string)==true){window.open(random_link_href);}}else{alert_string="Unable to find a suitable random link in "+max_num_iterations+" attempts.\n";window.alert(alert_string);}}// closes function followRandomLinkOnPage()addOnloadHook(function(){mw.util.addPortletLink('p-navigation','javascript:followRandomLinkOnPage()','Follow a lucky link!','ca-lucky','Follow a randomly chosen link on this page','@','');});//</pre>