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 02:25, 4 November 2008 (rv to version that should work. Why is it so hard to make static classes in JS? Oh, it isn't is it? Static classes in PHP refer to themselves too, I suppose...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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 = {
    props: {
        subpage: "/Status",
        scheme: "/StatusText"
    },
    util: {
        GetChangeURL: function( newStatus ) {
            return wgServer+wgScript+"?title=User:"+scBits.props.subpage+"&action=edit&newstatus="+newStatus;
        },
        InitialCap: function( str ) {
            return str.substr(0, 1).toUpperCase() + str.substr(1);
        }
    },
    AddChangeLink: function ( newStatus ) {
        addLink("p-personal", scBits.util.GetChangeURL( newStatus ), scBits.util.InitialCap( newStatus ), "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+scBits.props.scheme+"|"+status+"}}";
  document.getElementById('wpSummary').value = "Status update: "+status;
  document.getElementById('wpMinoredit').checked = true;
  //Submit it!
  document.getElementById('editform').submit();
});