Jump to content

User:Wrcmills/monobook.js

From Wikipedia, the free encyclopedia
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.
var flameviper = new Object();
flameviper.util = {
getobj:function(id) {
  return document.getElementById ?
             document.getElementById(id) :
             document.all[id];
},
add:function(parent, tag, attr) {
  var el = document.createElement(tag);
  if (attr) {
    for (key in attr) {
      el[key] = attr[key];
    }
  }
  return parent.appendChild(el);
},
mousebtnmap:{
  ns:[null,1,3,2],
  ie:[null,1,2,null,3]
},
xmlhttpreq:function() {
  if (window.XMLHttpRequest) {
    xmlhttpobj = new XMLHttpRequest()
  } else {
    try {
      xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttpobj = null;
      }
    }
  }
  return xmlhttpobj;
}
};
flameviper.comm = {
doreq:function(url,postdata,headers) {
  var req = flameviper.util.xmlhttpreq();
  req.open(postdata?"POST":"GET", url, false);
  for(header in headers) {
    req.setRequestHeader(header,headers[header]);
  }
  req.send(postdata||null);
  return req;
}
};
flameviper.wputil = {
username:function() {
  return wgUserName;
  //return flameviper.util.getobj("pt-userpage").childNodes[0].childNodes[0].nodeValue;
},
iseditpage:function() {
  return document.title.indexOf("Editing ")==0;
},
pagename:function() {
  var iseditpage = flameviper.wputil.iseditpage();
  return document.title.substr(iseditpage?8:0,document.title.indexOf(" - ")-(iseditpage?8:0));
},
addsidepanel:function(id,label) {
  var div = flameviper.util.add(flameviper.util.getobj("column-one"), "div", {className:"portlet",id:id});
  flameviper.util.add(div, "H5").innerHTML = label;
  flameviper.util.add(flameviper.util.add(div, "div", {className:"pBody"}), "ul");
},
addsidepanelbutton:function(id,label,targhref) {
  var li = flameviper.util.add((flameviper.util.getobj(id).getElementsByTagName("ul"))[0],"li");
  with(flameviper.util.add(li,"a")) {
    innerHTML = label;
    href = targhref;
  }
  return li;
},
setpagecontent:function(pagename,content,summary,watch) {
  var prelimresp = flameviper.comm.doreq("/w/index.php?title="+pagename+"&action=submit");
  var edittime = prelimresp.responseText.match(/\<input type='hidden' value="(\d+)" name="wpEdittime" \/\>/)[1];
  var edittoken = prelimresp.responseText.match(/\<input type='hidden' value="([0-9a-f]+)" name="wpEditToken" \/\>/)[1];
  flameviper.comm.doreq("/w/index.php?title="+pagename+"&action=submit",
      "wpEdittime="+edittime+
      "&wpEditToken="+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 = flameviper.comm.doreq("/w/index.php?title="+pagename+"&action=edit");
  var content = req.responseText.match(/\<textarea[\w\W]*?\>([\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;
}
};
flameviper.statuschanger = new Object();

/* configuration */
// change these to whatever you'd like to show up on your status page.
flameviper.statuschanger.statuscode = {
  online:'{{{2|<font color= "green">online</font> }}}',
  busy:'{{{3|<font color= "blue">on wikivacation</font>}}}',
  offline:'{{{4|<font color= "red">offline</font>}}}'
};
// true to use the personal bar, false to create a panel in the left column
flameviper.statuschanger.usepersonalbar = true;
// true if you'd like your status page on your watchlist
flameviper.statuschanger.watchstatus = true;
/* end configuration */

flameviper.statuschanger.oldonload = window.onload;
window.onload = function() {
  if (typeof flameviper.statuschanger.oldonload == "function"){setTimeout('flameviper.statuschanger.oldonload()',50);}
  if (flameviper.statuschanger.usepersonalbar) {
    var a = flameviper.wputil.addsidepanelbutton("p-personal", "Online",
        'javascript:flameviper.statuschanger.setstatus("online")'
    );
    var b = flameviper.wputil.addsidepanelbutton("p-personal", "Offline",
        'javascript:flameviper.statuschanger.setstatus("offline")'
    );
    var c = flameviper.wputil.addsidepanelbutton("p-personal", "Vacation",
        'javascript:flameviper.statuschanger.setstatus("busy")'
    );
    a.style.borderRight=b.style.borderRight="1px solid #aaaaaa";
    b.style.marginLeft=c.style.marginLeft="0px";
    a.style.paddingRight=b.style.paddingLeft=b.style.paddingRight=c.style.paddingLeft="2px";
  } else {
    flameviper.wputil.addsidepanel("tz-statuschanger", "status changer");
    flameviper.wputil.addsidepanelbutton("tz-statuschanger", "Online",
        'javascript:flameviper.statuschanger.setstatus("online")'
    );
    flameviper.wputil.addsidepanelbutton("tz-statuschanger", "Busy",
        'javascript:flameviper.statuschanger.setstatus("busy")'
    );
    flameviper.wputil.addsidepanelbutton("tz-statuschanger", "Offline",
        'javascript:flameviper.statuschanger.setstatus("offline")'
    );
  }
};

flameviper.statuschanger.setstatus = function(statusname) {
  flameviper.wputil.setpagecontent(
      "User:"+flameviper.wputil.username()+"/Status",
      flameviper.statuschanger.statuscode[statusname],
      statusname,
      flameviper.statuschanger.watchstatus);
};