Jump to content

User:Dgw/switchstatus.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dgw (talk | contribs) at 01:34, 4 November 2008 (If this works, I will have done my first coding in months. Fingers crossed... Code looks tidier, no?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
/* Misza13's Status Switcher Script */
// Modified by Voyagerfan5761 for some improvements

// Define some utility stuff
var scBits = {
    subpage: "/Status",
    scheme: "/StatusText",
    GetChangeURL: function( newStatus ) {
        return wgServer+wgScript+"?title=User:"+subpage+"&action=edit&newstatus="+newStatus;
    },
    AddChangeLink: function ( newStatus ) {
        addLink("p-personal", this.GetChangeURL( newStatus ), newStatus.substr(0, 1).toUpperCase() + newStatus.substr(1), "pt-status-" + newStatus, "I'm " + newStatus + "!", "", "pt-logout");
    }
}

// Do something
addOnloadHook(function (){
  //Add the links
  scBits.AddChangeLink( "in" );
  scBits.AddChangeLink( "busy" );
  scBits.AddChangeLink( "out" );
  if (location.href.indexOf("&action=edit&newstatus=") == -1) return; //Are we here to auto-edit the status?
  //Get new status
  statusRegExp = /&action=edit&newstatus=(.*)/;
  status = statusRegExp.exec(location.href)[1];
  //Modify the form
  document.getElementById('wpTextbox1').value = "{{User:"+wgUserName+scheme+"|"+status+"}}";
  document.getElementById('wpSummary').value = "Status update: "+status;
  document.getElementById('wpMinoredit').checked = true;
  //Submit it!
  document.getElementById('editform').submit();
});