Last active
August 29, 2015 14:22
-
-
Save reimertz/e40cc71d525e17797654 to your computer and use it in GitHub Desktop.
WikiWalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. Go to a random english wikipedia article | |
2. Paste the code below in the console | |
3. Take a WikiWalk. :D | |
*/ | |
function wikiWalk(){ | |
var seeAlso = $.find("h2 span:contains('See also'):first"), | |
related = $(seeAlso).parent().nextAll('ul:first').find('li a'), | |
next = related[Math.floor(Math.random() * (related.length-1))]; | |
if(!next) { | |
var ramdomLink = $('#bodyContent a'); | |
while(true){ | |
next = ramdomLink[Math.floor(Math.random() * (ramdomLink.length-1))]; | |
if(next.href && (next.href.indexOf('wikipedia.org') > -1)){ | |
break; | |
} | |
} | |
} | |
//for you josh | |
if(document.location.href == "http://en.wikipedia.org/wiki/Philosophy"){ | |
alert('Philosophy!'); | |
} | |
console.log("wikiwalking to: " + next.href); | |
$.ajax(next.href) | |
.complete(function(result){ | |
document.documentElement.innerHTML = result.responseText; | |
setTimeout(function(){ | |
wikiWalk(); | |
}, 1000); | |
}) | |
} | |
wikiWalk(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment