Jump to content

User:Vox Rationis/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Vox Rationis (talk | contribs) at 02:32, 14 February 2007 (added status script). 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.
//<nowiki> Admin-like RC Patrol tools

//document.write('<script type="text/javascript" src="' 
//             + 'http://en.wikipedia.org/w/index.php?title=User:VoA/monobook.js' 
//             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

//</nowiki>[[Category:Wikipedians who use RC script ]]

//<pre><nowiki>
// VIEW SOURCE
addOnloadHook(function () {
  if (location.href.indexOf('viewsource=1') != -1) {
    sl = document.getElementById('wpSummaryLabel'); sl.parentNode.removeChild(sl);
    ed = document.getElementById('wpSummary').parentNode; ed.parentNode.removeChild(ed);
    return;
  }
  editbutton = document.getElementById('ca-edit');
  if (editbutton && location.href.indexOf('action=edit')==-1) {
    editlink = editbutton.getElementsByTagName('a')[0].href + '&viewsource=1';
    tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    na = document.createElement('a');
    na.href = editlink; na.appendChild(document.createTextNode('view source'));
    li = document.createElement('li'); li.id = 'ca-viewsource'; li.appendChild(na);
    tabs.insertBefore(li,editbutton);
  }
});

//</nowiki></pre>

//<nowiki>

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


/* configuration */

// change these to whatever you'd like to show up on your status page.  you can add new lines in
// the same format provided there is a comma at the end of each line but the last one.  you can
// also use wikimarkup here to, for example, display an image instead of text.
topaz.statuschanger.statuscode = {
  online:'<font color="green">online</font>',
  busy:'<font color="orange">busy</font>',
  offline:'<font color="red">offline</font>'
};

// this will make wikimarkup work in your stauscodes but will disable auto-updating 
topaz.statuschanger.enablewikimarkup = false;

// 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";
        }
      }
    }
  }

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

  topaz.statuschanger.update();
};

topaz.statuschanger.setstatus = function(statusname) {
  topaz.wputil.setpagecontent(
      "User:"+topaz.wputil.username()+"/Status",

      (!topaz.statuschanger.enablewikimarkup ?
          '<includeonly><span class="topaz.statuschanger.inlinestatus.'
          + escape(topaz.wputil.username())
          + '"></includeonly>'
      : '') +

      topaz.statuschanger.statuscode[statusname] +

      (!topaz.statuschanger.enablewikimarkup ?
          '<includeonly></span></includeonly>'
      : '') +

      '<span class="topaz.statuschanger.curstatus.'+escape(topaz.wputil.username()) +
      '" style="display:none">'+statusname+'</span>',

      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";
        }
      }
    }

    if (!topaz.statuschanger.enablewikimarkup) {
      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>