User:Bo98/statusupdate.js

if (wgPageName.search('User:'+wgUserName) != -1 || wgPageName.search('User talk:'+wgUserName) != -1) { addOnloadHook(statusLinks); };

function statusLinks { if (typeof hideStatus == 'undefined') hideStatus = false; if (document.getElementById('user-status')) { if (hideStatus) document.getElementById('user-status').style.visibility = 'visible'; for (var sp in document.getElementById('user-status').getElementsByTagName('span')) { document.getElementById('user-status').getElementsByTagName('span')[sp].style.cursor = 'pointer'; 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+'/StatusChanger&summary='+summ+'&minor=1&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); }; };