User:Quarenon/livestatsviewer.js

// Fetch player name from the tag and load external data function initLiveStats { div = document.getElementById("liveStatsBox"); if (div != null) { player = div.getAttribute('title'); loader = document.createElement('script'); loader.setAttribute('type', 'text/javascript'); loader.setAttribute('language', 'JavaScript'); loader.setAttribute('src', 'http://infinisoft.ath.cx/rs/livestats.php?player=' + player); document.getElementsByTagName("head")[0].appendChild(loader); div.innerHTML = 'Live stats for ' + player + ' are loading...'; } }

// Called once stats are loaded, and we are ready to show them. function doLiveStats { div = document.getElementById("liveStatsBox");

if (!liveStats) { div.innerHTML = 'Stats loading error!<\/b>'; return; } else { div.innerHTML = ''; }

var table = document.createElement('table'); table.setAttribute('class', 'wikitable'); table.setAttribute('className', 'wikitable');

// Table column headers var tr = document.createElement('tr'); var th = document.createElement('th'); th.appendChild(document.createTextNode('Skill')); tr.appendChild(th); var th = document.createElement('th'); th.appendChild(document.createTextNode('Rank')); tr.appendChild(th); var th = document.createElement('th'); th.appendChild(document.createTextNode('Level')); tr.appendChild(th); var th = document.createElement('th'); th.appendChild(document.createTextNode('XP')); tr.appendChild(th); table.appendChild(tr);

for (i = 0; i < liveStats.length; i++) { var tr = document.createElement('tr'); var td = document.createElement('td'); td.appendChild(document.createTextNode(liveStats[i]["name"])); td.setAttribute('style', 'font-weight: bold'); tr.appendChild(td); var td = document.createElement('td'); td.appendChild(document.createTextNode(liveStats[i]["rank"])); tr.appendChild(td); var td = document.createElement('td'); td.appendChild(document.createTextNode(liveStats[i]["level"])); tr.appendChild(td); var td = document.createElement('td'); td.appendChild(document.createTextNode(liveStats[i]["xp"])); tr.appendChild(td); table.appendChild(tr); }	div.appendChild(table); }

addOnloadHook(initLiveStats);