Skip to content

Instantly share code, notes, and snippets.

@reimertz
Last active August 29, 2015 14:22
Show Gist options
  • Save reimertz/e40cc71d525e17797654 to your computer and use it in GitHub Desktop.
Save reimertz/e40cc71d525e17797654 to your computer and use it in GitHub Desktop.
WikiWalk
/*
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