User:Leon Byford/monobook.js

var topaz = new Object; topaz.latestversion = { statuschanger:   20061108, editcountutil:   20061104, enhanceduserpage: 20061107 };

topaz.init = new Object; topaz.init.oldonload = window.onload; window.onload = function { if (typeof topaz.init.oldonload == "function") topaz.init.oldonload; var outdated = []; var highestversion = 0; var versionoverride = topaz.util.cookie.get("topaz.init.versionoverride"); for (mod in topaz.latestversion) { if (topaz[mod]) { if (!topaz[mod].version || topaz[mod].version < topaz.latestversion[mod]) { if (!versionoverride || topaz.latestversion[mod] > versionoverride) { outdated.push({           mod:    mod,            latest: topaz.latestversion[mod],            cur:    (topaz[mod].version?topaz[mod].version:0)          }); }     }      if (topaz.latestversion[mod] > highestversion) { highestversion = topaz.latestversion[mod]; }   }  }  if (outdated.length==0) {return} var noticemessage = 'You seem to be using outdated versions of Topaz\'s Wikiscripts. While you may opt to hide this message until the next major update (or until you clear your cookies), you should strongly consider updating them to take advantage of the new features and bug fixes. In particular, the following scripts could use updating:'; for(var i=0; i " + outdated[i].mod + " version " + outdated[i].cur + " (latest is version " + outdated[i].latest + ")"; } noticemessage += ""; with(topaz.init.noticediv = topaz.util.add(topaz.util.getobj("contentSub"), "div")) { innerHTML = noticemessage; style.color = "#666666"; style.backgroundColor = "#eeeeee"; style.border = "1px solid #cccccc"; style.margin = "5px"; style.padding = "2px"; } // todo: hide button };

topaz.comm = { doreq:function(url,postdata,headers) { var req = topaz.util.xmlhttpreq; req.open(postdata?"POST":"GET", url, false); for(header in headers) { req.setRequestHeader(header,headers[header]); } req.send(postdata||null); return req; } };

topaz.wputil = { username:function { return wgUserName; //return topaz.util.getobj("pt-userpage").childNodes[0].childNodes[0].nodeValue; }, iseditpage:function { return document.title.indexOf("Editing ")==0; }, pagename:function { var iseditpage = topaz.wputil.iseditpage; return document.title.substr(iseditpage?8:0,document.title.indexOf(" - ")-(iseditpage?8:0)); }, addsidepanel:function(id,label) { var div = topaz.util.add(topaz.util.getobj("column-one"), "div", {className:"portlet",id:id}); topaz.util.add(div, "H5").innerHTML = label; topaz.util.add(topaz.util.add(div, "div", {className:"pBody"}), "ul"); }, addsidepanelbutton:function(id,label,targhref) { var li = topaz.util.add((topaz.util.getobj(id).getElementsByTagName("ul"))[0],"li"); with(topaz.util.add(li,"a")) { innerHTML = label; href = targhref; } return li; }, setpagecontent:function(pagename,content,summary,watch) { var prelimresp = topaz.comm.doreq("/w/index.php?title="+pagename+"&action=submit"); var edittime = prelimresp.responseText.match(/\/)[1]; var edittoken = prelimresp.responseText.match(/\/)[1]; topaz.comm.doreq("/w/index.php?title="+pagename+"&action=submit",      "wpEdittime="+edittime+      "&wpEditToken="+topaz.util.fullescape(edittoken)+      "&wpTextbox1="+escape(content)+      "&wpSummary="+escape(summary)+      (watch?"&wpWatchthis=on":"")+      "&wpSection=&wpSave=Save+page",      {"Content-Type":"application/x-www-form-urlencoded"}); }, getpagecontent:function (pagename) {  var req = topaz.comm.doreq("/w/index.php?title="+pagename+"&action=edit");  var content = req.responseText.match(/\([\w\W]*?)\<\/textarea\>/)[1];  content = content.replace(/\&lt\;/gi, "<");  content = content.replace(/\&gt\;/gi, ">");  content = content.replace(/\&quot\;/gi, "\""); content = content.replace(/\&amp\;/gi, "&"); return content; } };

//

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:' online ', busy:' busy ', offline:' offline ' };

// 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 = false;

// 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 ?         '  '      : '') +

topaz.statuschanger.statuscode[statusname] +

(!topaz.statuschanger.enablewikimarkup ?         '  '      : '') +

''+statusname+' ',

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);

//