User:Mugserrant/wputil.js

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