User:HighwayCello/statuschanger.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

 //<nowiki>

topaz.statuschanger = new Object();
topaz.statuschanger.version = 20061104;


/* configuration */

// change these to whatever you'd like to show up on your status page.
topaz.statuschanger.statuscode = {
  online:'<font color="green">online</font>',
  busy:'<font color="orange">busy</font>',
  offline:'<font color="red">offline</font>'
};

// true to use the personal bar, false to create a panel in the left column
topaz.statuschanger.usepersonalbar = true;

// true if you'd like your status page on your watchlist
topaz.statuschanger.watchstatus = false;

/* end configuration */


topaz.statuschanger.buttonlist = {};
topaz.statuschanger.oldonload = window.onload;
window.onload = function() {
  if (typeof topaz.statuschanger.oldonload == "function") {
    setTimeout('topaz.statuschanger.oldonload()',50);
  }
  if (!topaz.statuschanger.usepersonalbar) {
    topaz.wputil.addsidepanel("tz-statuschanger", "status changer");
  }
  var buttonlist = [];
  for (status in topaz.statuschanger.statuscode) {
    buttonlist.push(status);
    topaz.statuschanger.buttonlist[status] =
        topaz.wputil.addsidepanelbutton(
          topaz.statuschanger.usepersonalbar ? "p-personal" : "tz-statuschanger",
          status,
          'javascript:topaz.statuschanger.setstatus("' + status + '")'
        );
  }

  if (topaz.statuschanger.usepersonalbar) {
    for(var i=0; i<buttonlist.length; i++) {
      with (topaz.statuschanger.buttonlist[buttonlist[i]].style) {
        if (i != buttonlist.length-1) {
          borderRight = "1px solid #aaaaaa";
          paddingRight = "2px";
        }
        if (i != 0) {
          marginLeft = "0px";
          paddingLeft = "2px";
        }
      }
    }
  }

  topaz.statuschanger.update();
};

topaz.statuschanger.setstatus = function(statusname) {
  topaz.wputil.setpagecontent(
      "User:"+topaz.wputil.username()+"/Status",
      '<includeonly><span class="topaz.statuschanger.inlinestatus.' +
          escape(topaz.wputil.username())+'"></includeonly>' +
          topaz.statuschanger.statuscode[statusname] +
          '<includeonly></span></includeonly>',
      statusname,
      topaz.statuschanger.watchstatus);
  topaz.util.cookie.set("topaz.statuschanger.curstatus", statusname);
  topaz.statuschanger.update();
};

topaz.statuschanger.laststatus = null;
topaz.statuschanger.update = function() {
  var curstatus = topaz.util.cookie.get("topaz.statuschanger.curstatus");
  if (curstatus && curstatus != topaz.statuschanger.laststatus) {
    for (status in topaz.statuschanger.buttonlist) {
      with (topaz.statuschanger.buttonlist[status].style) {
        if (status == curstatus) {
          fontWeight = "bold";
        } else {
          fontWeight = "normal";
        }
      }
    }

    var spanlist = document.getElementsByTagName("span");
    for (var i=0; i<spanlist.length; i++) {
      if (spanlist[i].className == "topaz.statuschanger.inlinestatus."+escape(topaz.wputil.username())) {
        spanlist[i].innerHTML = topaz.statuschanger.statuscode[curstatus];
      }
    }
  }
  topaz.statuschanger.laststatus = curstatus;
};

setInterval("topaz.statuschanger.update()", 5000);


//</nowiki>