Skip to content

Instantly share code, notes, and snippets.

@infoburp
Forked from steren/index.html
Last active August 29, 2015 14:07
Show Gist options
  • Save infoburp/9a9ae2e37ba19c576625 to your computer and use it in GitHub Desktop.
Save infoburp/9a9ae2e37ba19c576625 to your computer and use it in GitHub Desktop.
<div id="insertTest"></div>
<script>
var wikipediaHTMLResult = function(data) {
var readData = $('<div>' + data.parse.text.* + '</div>');
// handle redirects
var redirect = readData.find('li:contains("REDIRECT") a').text();
if(redirect != '') {
callWikipediaAPI(redirect);
return;
}
var box = readData.find('.infobox');
var binomialName = box.find('.binomial').text();
var fishName = box.find('th').first().text();
var imageURL = null;
// Check if page has images
if(data.parse.images.length >= 1) {
imageURL = box.find('img').first().attr('src');
}
$('#insertTest').append('<div><img src="'+ imageURL + '"/>'+ fishName +' <i>('+ binomialName +')</i></div>');
};
function callWikipediaAPI(wikipediaPage) {
// http://www.mediawiki.org/wiki/API:Parsing_wikitext#parse
$.getJSON('http://en.wikipedia.org/w/api.php?action=parse&format=json&callback=?', {page:wikipediaPage, prop:'text|images', uselang:'en'}, wikipediaHTMLResult);
}
callWikipediaAPI('Aholehole');
</script>
$.getJSON("http://en.wikipedia.org/w/api.php?action=parse&format=json&callback=?", {page:pageName, prop:"text"}, wikipediaHTMLResult);
$.getJSON("http://en.wikipedia.org/w/api.php?action=query&format=json&callback=?", {titles:pageName, prop: "images"}, wikipediaImageResult);
$.getJSON("http://en.wikipedia.org/w/api.php?action=query&format=json&callback=?", {titles:pageName, prop: "revisions", rvprop:"content"}, wikipediaPageResult);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment