Jump to content

User:2D/statusupdater.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function formatResponse(response) {
    try {
        response = response.query.pages;
        for (var property in response)
            return response[property];
    } catch (e) {
    }
}
function zeroPad(str) {
return ("0" + str).slice(-2);
}
function status()
{
    var news = prompt("What is your new status?");
    news = encodeURIComponent(news);
    var req = sajax_init_object();
    var req1 = sajax_init_object();
    req.open("GET", wgScriptPath + "/api.php?action=query&prop=info|revisions&format=json&intoken=edit&rvprop=content|timestamp&titles=" + encodeURIComponent("User:" + wgUserName + "/Status"), false);
    req.send(null);
    var info = formatResponse(eval("(" + req.responseText + ")"));
    var date = new Date();
    var startTime = date.getUTCFullYear() + zeroPad(date.getUTCMonth() + 1) + zeroPad(date.getUTCDate()) + zeroPad(date.getUTCHours()) + zeroPad(date.getUTCMinutes()) + zeroPad(date.getUTCSeconds());
    var editTime = (info.revisions[0] ? info.revisions[0].timestamp.replace(/[^0-9]/g, "") : startTime); 
    var content = (info.revisions[0]["*"] ? info.revisions[0]["*"] : "");
    var editToken = info.edittoken;
    var postData = "wpTextbox1=" + news + "&wpSave=save&wpMinoredit=1&wpEditToken=" + encodeURIComponent(editToken) + "&wpSummary=Changing status to: " + news
        + "&wpEdittime=" + editTime
        + "&wpStarttime=" + startTime;
    req1.open("POST", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + encodeURIComponent("User:" + wgUserName + "/Status") + "&action=submit", false);
    req1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req1.setRequestHeader("Content-Length", postData.length);
    req1.send(postData);
return;
}
function start()
{
    addPortletLink("p-cactions","javascript:status()","status","ca-status");
}
$(start);