User:Whiteknight/remotetalk2.js

var rt = { rt.span: "WKRTSpan", rt.iframe: null, rt.alias: new Array, };

rt.getIFrame = function { if(rt.iframe == null) rt.iframe = wk.makeElement("iframe", {width:"100%", height:"550px"}); return rt.iframe; }

rt.talkLinks = function { var frame = wk.makeElement("div"); for(i = 0; i < rt.alias.length; i++) { var link = rt.createLink(rt.alias[i][0], rt.alias[i][1], rt.alias[i][2], rt.alias[i][3]); frame.appendChild(link); frame.appendChild(document.createTextNode(" — ")); }  link = wk.makeElement("a", {href:"#" + rt.span}, "Remove"); link.onclick = rt.initFrame; frame.appendChild(link); return frame; }

rt.createLink = function(project, username, linkname) { if(username == "") username = wgUserName; if(project == "") project  = "wikibooks"; if(linkname == "") linkname = username + "@" + project; username = username.replace(" ", "_"); var link = wk.makeElement("a", {href:"#" + rt.span}, linkname); link.onclick = function{ rt.getTalkPage(lang, project, username)}; return link; }

rt.getTalkPage = function (lang, project, username) { var talkurl = "http://" + lang + "." + project + ".org" + "/w/index.php?title=User_talk:" + username + "&action=view&printable=yes"; var frame = wk.spanText(rt.span, ""); var iframe = rt.getIFrame; iframe.setAttribute("src", talkurl); frame.appendChild(rt.talkLinks); frame.appendChild(iframe); frame.appendChild(rt.talkLinks); }

rt.getAlias = function(frame) { var text = frame.innerHTML; var links = text.split(","); for(var i = 0; i < links.length; i++) { var junk = links[i].split("@"); var name = junk[0]; var project = junk[1]; rt.alias.push([project, name]) }

}

rt.initFrame = function { var frame = wk.spanText(rt.span, ""); if(frame != null) { rt.getAlias(frame); frame.appendChild(rt.talkLinks); } }

if(typeof wk == "object" && wk.testVersion(2.0)) { addOnloadHook(rt.initFrame); }