User:Svip/monobook.js

var barWidth = 200; var topAmount = 500; var currentAmount = 0;

function updateDonationNotice { if(!document.getElementById("donation-progress-number")) return; getDonation; }

addOnloadHook(updateDonationNotice);

function getDonation { var url = "/api.php?action=query&meta=allmessages&ammessages=donation-amount&amlang=en&format=xml"; ajax(url, getDonationEnd, []); }

function getDonationEnd(xml, data) { var doc = xml.documentElement; var currentAmount = parseInt(doc.getElementsByTagName("message")[0].firstChild.data); var nowWidth = (currentAmount/topAmount)*barWidth; var number = document.getElementById("donation-progress-number"); number.innerHTML = currentAmount; var progBar = document.getElementById("donation-progress-indicator"); alert(progBar); progBar.setAttribute("style", "width: " + nowWidth + "px"); }

function ajax(url, callbackFunction, data) { var request = new XMLHttpRequest; request.open("GET", url, true); //request.setRequestHeader("Content-Type", //                         "application/x-www-form-urlencoded"); request.onreadystatechange = function { var done = 4, ok = 200; if (request.readyState == done) { if (request.status == ok) { if (request.responseXML) { callbackFunction(request.responseXML, data); }     } else { if (request.responseXML) { alert(request.responseXML); } else { alert('Fejl: Serveren stak mig i ryggen og skred. ' + request.status) }     }    }  };  request.send(null); }