User:Jon513'sSlave/monobook.js

if (wgNamespaceNumber ==0) addOnloadHook(function{

//create object to store all values var allInfo=new Object; //create element to display rating var ratingArea= document.createElement("span"); //feedHandler to keep track of when feed finish var feedHandler=[0,0]; //title to use in query var escapedTitle=escape(wgTitle);

//helper function to tell when all feeds finish and direct to error or process data function constantlyCheckFeeds { var completed=true; var error=false; for(i in feedHandler) {     if (feedHandler[i]== -1) error=true; if (feedHandler[i]== 0) completed=false; }

if (error) {   error; }else if(completed) {   processData; }else {   setTimeout(constantlyCheckFeeds, 500); } } function error {  ratingArea.innerHTML="error retrieving data"; } function processData { try{ var toDisplay=""; toDisplay+="there are "+allInfo.categories.length+" categories on the page " ; toDisplay+="there are "+allInfo.templates.length+" templates on the page " ; toDisplay+="there are "+allInfo.images.length+" images on the page " ; toDisplay+="there are "+allInfo.extlinks.length+" external links on the page " ; toDisplay+="there are "+allInfo.links.length+" interwiki links on the page " ; toDisplay+="the article is "+allInfo.lengthInBytes+" bytes long " ; toDisplay+="it was last edited on "+allInfo.dateOfLastTouched+" " ; toDisplay+="the copyright is "+allInfo.copyright+"!"; ratingArea.innerHTML=toDisplay; }catch (e) { ratingArea.innerHTML="ERROR! ("+e.message+")"; }

}

//position element correctly document.getElementById("content").insertBefore( ratingArea, document.getElementsByTagName("h1")[0]); ratingArea.innerHTML="Loading..."; ratingArea.style.position='absolute'; ratingArea.style.right='10px'; ratingArea.style.marginRight = '25px'; //request Page info var req = null; if(window.XMLHttpRequest) req = new XMLHttpRequest; else if (window.ActiveXObject) req = new ActiveXObject(Microsoft.XMLHTTP); req.onreadystatechange = function {   if(req.readyState == 4) {     if(req.status == 200) {          ratingArea.innerHTML+="feed One received..."; var PageInfo= eval('(' + req.responseText + ')'); allInfo.categories=PageInfo["query"]["pages"][wgArticleId]["categories"]; allInfo.templates=PageInfo["query"]["pages"][wgArticleId]["templates"]; allInfo.images=PageInfo["query"]["pages"][wgArticleId]["images"]; allInfo.extlinks=PageInfo["query"]["pages"][wgArticleId]["extlinks"]; allInfo.links=PageInfo["query"]["pages"][wgArticleId]["links"]; allInfo.lengthInBytes=PageInfo["query"]["pages"][wgArticleId]["length"]; allInfo.dateOfLastTouched=PageInfo["query"]["pages"][wgArticleId]["touched"];

feedHandler[0]=1; }	   else {     ratingArea.innerHTML="Error: returned status code " + req.status + " " + req.statusText; feedHandler[0]=-1; }	 } };

req.open("GET", "http://en.wikipedia.org/w/api.php?action=query&titles="+escapedTitle+"&prop=categories|templates|images|langlinks|extlinks|links|revisions|info&format=json&rvdir=newer&rvlimit=1", true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(null);

//request processing creteria var req2 = null; if(window.XMLHttpRequest) req2 = new XMLHttpRequest; else if (window.ActiveXObject) req2 = new ActiveXObject(Microsoft.XMLHTTP); req2.onreadystatechange = function {   if(req2.readyState == 4) {     if(req2.status == 200) {         ratingArea.innerHTML+="feed Two received..."; var SiteInfo= eval('(' + req2.responseText + ')') allInfo.copyright=SiteInfo["query"]["general"]["rights"]; feedHandler[1]=1; }	   else {     ratingArea.innerHTML="Error: returned status code " + req2.status + " " + req2.statusText; feedHandler[1]=-1; }	 } }; req2.open("GET", "http://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&format=json", true); req2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req2.send(null);

constantlyCheckFeeds;

});