Jump to content

User:Dgw/switchstatus.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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 mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=User:"+mw.config.get('wgUserName')+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:"+mw.config.get('wgUserName')+scBits.props.scheme+"|"+status+"}}";
  document.getElementById('wpSummary').value = "Status update: "+status;
  document.getElementById('wpMinoredit').checked = true;
  //Submit it!
  document.getElementById('editform').submit();
});