User:Dgw/switchstatus.js

/* 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();

});