Source: WikipediaReader.js

/**
 * Reads the article of the specified Wikipedia-URL
 * 
 * @param {string} url A url to a Wikipedia article
 */
readWikipediaArticle = function(url)
{
	document.getElementById("status_icon").src = "images/yellow.png";
	
    var i = url.lastIndexOf("/");

    // extract the url start and the page name
    var url_start = url.substring(0, i - 4);
    var pageTitle = url.substring(i + 1, url.length);
    
    // compose the Wikipedia API url
    var api_url = url_start + "w/api.php?action=query&format=json&prop=extracts&explaintext=1&titles=" + pageTitle + "&callback=?";
    
    if (api_url.indexOf("wikipedia.org") == -1) {
    	document.getElementById("status_icon").src = "images/red.png";
    	return;
    }
	
    // send a GET-request to the Wikipedia API url
    $.ajax({
		type : "GET",
		url : api_url,
		contentType : "application/json; charset=utf-8",
		async : false,
		dataType : "json",
		success : function(data, textStatus, jqXHR)
		{
			var pages = data.query.pages;
			
			for (var page in pages) {
			    if (pages.hasOwnProperty(page) && pages[page].extract != null) {
			        var text = pages[page].extract;
			        
			        globalText = text;
			        globalTextArray = globalText.match(/\w+/g);
			        
			        for (var i = 0; i < globalTextArray.length; i++) {
			        	globalTextArray[i] = globalTextArray[i].toLowerCase();
			        }
			        
			        document.getElementById("status_icon").src = "images/green.png";
			        
			        console.log("done");
			        return;
			    }
			}

	    	document.getElementById("status_icon").src = "images/red.png";
		},
		error : function(errorMessage)
		{
	    	document.getElementById("status_icon").src = "images/red.png";
		}
	});
}