User:RadicalOne/vector.js

addOnloadHook(statusLinks);

function statusLinks { if (document.getElementById('user-status')) { for (var sp in document.getElementById('user-status').getElementsByTagName('span')) { addHandler(document.getElementById('user-status').getElementsByTagName('span')[sp], 'click', updateMyStatus); }; }; };

function updateMyStatus { var statusText = this.innerHTML; var summ = 'updating status'; var token;

apicall('action=query&prop=info&intoken=edit&titles=User:'+wgUserName+'/Status', function(res) {   for (var page in res.query.pages) {      token= res.query.pages[page].edittoken.replace(/\+\\$/g,'%2B%5C');    };  });

apicall('action=edit&title=User:'+wgUserName+'/Status&summary='+summ+'&recreate=1&text='+statusText+'&token='+token, function(res) {   if (res.edit.result != "Success") {      alert("Couldn't edit the status page.");    };  });

window.location.reload; };

function apicall(query, callback) { try { var xmlRequest = new XMLHttpRequest; } catch(e) { try { var xmlRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { throw "Could not create an XmlHttpRequest"; }     }    }

xmlRequest.open('POST', wgScriptPath+'/api.php', false); xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlRequest.send(query+'&format=json'); var xmlResponse = new Function("return "+xmlRequest.responseText); if (!xmlResponse) { alert("Couldn't access the API."); } else { callback(xmlResponse); }; };