Hacked into submission
This commit is contained in:
parent
9303e6f8e5
commit
c96208d569
|
@ -3,8 +3,9 @@
|
|||
var maxScrollback = 500;
|
||||
var networks = {};
|
||||
|
||||
function networkConnect(network, baseURL, authtok) {
|
||||
function networkConnect(baseURL, authtok) {
|
||||
var eventSource;
|
||||
var network = "server"; // XXX: remove this kludge!
|
||||
var element = getTemplate("server-channels");
|
||||
var channels = element.getElementsByClassName("channels")[0];
|
||||
var roomElement = element.getElementsByClassName("server")[0];
|
||||
|
@ -68,8 +69,8 @@ function networkConnect(network, baseURL, authtok) {
|
|||
|
||||
var form = new FormData();
|
||||
form.append("type", "command");
|
||||
form.append("network", "slashnet");
|
||||
form.append("auth", authtok);
|
||||
form.append("network", network);
|
||||
form.append("target", target);
|
||||
form.append("text", text);
|
||||
|
||||
|
@ -93,7 +94,7 @@ function networkConnect(network, baseURL, authtok) {
|
|||
}
|
||||
networks[network] = element;
|
||||
|
||||
var pullURL = baseURL + "?network=" + encodeURIComponent(network) + "&auth=" + encodeURIComponent(authtok);
|
||||
var pullURL = baseURL + "?auth=" + encodeURIComponent(authtok);
|
||||
eventSource = new EventSource(pullURL);
|
||||
eventSource.addEventListener("message", handleEventSourceMessage);
|
||||
eventSource.addEventListener("error", handleEventSourceError);
|
||||
|
|
178
room.js
178
room.js
|
@ -1,10 +1,10 @@
|
|||
function djbhash(a) {
|
||||
var r = 5381;
|
||||
var r = 5381;
|
||||
|
||||
for (var i = 0; i < a.length; i += 1) {
|
||||
r = (((r << 5) + r) + a.charCodeAt(i)) & 0xffff;
|
||||
}
|
||||
return r;
|
||||
for (var i = 0; i < a.length; i += 1) {
|
||||
r = (((r << 5) + r) + a.charCodeAt(i)) & 0xffff;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function purtify(text) {
|
||||
|
@ -54,109 +54,111 @@ function kiboze(this_is_currently_busted) {
|
|||
var visibleRoom;
|
||||
|
||||
function newRoom(element, network, name, maxSize) {
|
||||
var messages = getTemplate("messages");
|
||||
var lastmsg;
|
||||
if (! maxSize) {
|
||||
maxSize = 500;
|
||||
}
|
||||
var messages = getTemplate("messages");
|
||||
var lastmsg;
|
||||
if (! maxSize) {
|
||||
maxSize = 500;
|
||||
}
|
||||
|
||||
function purtify(fullSender, command, sender, args, txt) {
|
||||
var txtElement = document.createElement("span");
|
||||
var msg = chrome.i18n.getMessage(command + "Command", [fullSender, command, sender, name, args, txt]);
|
||||
if (! msg) {
|
||||
msg = chrome.i18n.getMessage("unknownCommand", [fullSender, command, sender, name, String(args), txt]);
|
||||
}
|
||||
function purtify(fullSender, command, sender, args, txt) {
|
||||
var txtElement = document.createElement("span");
|
||||
var msg = chrome.i18n.getMessage(command + "Command", [fullSender, command, sender, name, args, txt]);
|
||||
if (! msg) {
|
||||
msg = chrome.i18n.getMessage("unknownCommand", [fullSender, command, sender, name, String(args), txt]);
|
||||
}
|
||||
|
||||
var rhs = msg;
|
||||
var match;
|
||||
var rhs = msg;
|
||||
var match;
|
||||
|
||||
while ((match = urlRe.exec(rhs)) != null) {
|
||||
var before = rhs.substr(0, match.index);
|
||||
var a = document.createElement("a");
|
||||
var href = match[0];
|
||||
while ((match = urlRe.exec(rhs)) != null) {
|
||||
var before = rhs.substr(0, match.index);
|
||||
var a = document.createElement("a");
|
||||
var href = match[0];
|
||||
|
||||
if (href.indexOf("hxx") == 0) {
|
||||
href = "htt" + href.substr(3);
|
||||
}
|
||||
a.href = href
|
||||
a.target = "_blank";
|
||||
a.appendChild(document.createTextNode(match[0]));
|
||||
txtElement.appendChild(document.createTextNode(before));
|
||||
txtElement.appendChild(a);
|
||||
rhs = rhs.substr(match.index + match[0].length);
|
||||
}
|
||||
txtElement.appendChild(document.createTextNode(rhs));
|
||||
if (href.indexOf("hxx") == 0) {
|
||||
href = "htt" + href.substr(3);
|
||||
}
|
||||
a.href = href
|
||||
a.target = "_blank";
|
||||
a.appendChild(document.createTextNode(match[0]));
|
||||
txtElement.appendChild(document.createTextNode(before));
|
||||
txtElement.appendChild(a);
|
||||
rhs = rhs.substr(match.index + match[0].length);
|
||||
}
|
||||
txtElement.appendChild(document.createTextNode(rhs));
|
||||
|
||||
return txtElement;
|
||||
}
|
||||
return txtElement;
|
||||
}
|
||||
|
||||
|
||||
element.addMessage = function(timestamp, fullSender, command, sender, args, txt) {
|
||||
var message = getTemplate("message");
|
||||
element.addMessage = function(timestamp, fullSender, command, sender, args, txt) {
|
||||
var message = getTemplate("message");
|
||||
|
||||
var eTimestamp = message.getElementsByClassName("timestamp")[0];
|
||||
var eSource = message.getElementsByClassName("source")[0];
|
||||
var eContent = message.getElementsByClassName("content")[0];
|
||||
var eTimestamp = message.getElementsByClassName("timestamp")[0];
|
||||
var eSource = message.getElementsByClassName("source")[0];
|
||||
var eContent = message.getElementsByClassName("content")[0];
|
||||
|
||||
message.classList.add(command);
|
||||
if (sender == ".") {
|
||||
message.classList.add("self");
|
||||
}
|
||||
message.classList.add(command);
|
||||
if (sender == ".") {
|
||||
message.classList.add("self");
|
||||
}
|
||||
|
||||
eTimestamp.textContent = timestamp.toLocaleTimeString();
|
||||
eSource.textContent = sender;
|
||||
eSource.setAttribute("colornumber", djbhash(sender) % 31);
|
||||
eContent.appendChild(purtify(fullSender, command, sender, args, txt));
|
||||
eTimestamp.textContent = timestamp.toLocaleTimeString();
|
||||
eSource.textContent = sender;
|
||||
eSource.setAttribute("colornumber", djbhash(sender) % 31);
|
||||
eContent.appendChild(purtify(fullSender, command, sender, args, txt));
|
||||
|
||||
messages.appendChild(message);
|
||||
messages.appendChild(message);
|
||||
|
||||
while (messages.childNodes.length > maxSize) {
|
||||
messages.removeChild(messages.firstChild);
|
||||
}
|
||||
while (messages.childNodes.length > maxSize) {
|
||||
messages.removeChild(messages.firstChild);
|
||||
}
|
||||
|
||||
lastmsg = message;
|
||||
lastmsg = message;
|
||||
|
||||
if (visibleRoom == element) {
|
||||
lastmsg.scrollIntoView(false);
|
||||
}
|
||||
}
|
||||
if (visibleRoom == element) {
|
||||
lastmsg.scrollIntoView(false);
|
||||
}
|
||||
}
|
||||
|
||||
element.hide = function() {
|
||||
element.classList.remove("selected");
|
||||
messages.style.display = "none";
|
||||
}
|
||||
element.hide = function() {
|
||||
element.classList.remove("selected");
|
||||
messages.style.display = "none";
|
||||
}
|
||||
|
||||
element.show = function() {
|
||||
if (visibleRoom) {
|
||||
visibleRoom.hide()
|
||||
}
|
||||
element.classList.add("selected");
|
||||
messages.style.display = null;
|
||||
lastmsg.scrollIntoView(false);
|
||||
visibleRoom = element;
|
||||
}
|
||||
element.show = function() {
|
||||
if (visibleRoom) {
|
||||
visibleRoom.hide()
|
||||
}
|
||||
element.classList.add("selected");
|
||||
messages.style.display = null;
|
||||
lastmsg.scrollIntoView(false);
|
||||
visibleRoom = element;
|
||||
}
|
||||
|
||||
element.send = function(text) {
|
||||
network.send(name, text);
|
||||
}
|
||||
element.send = function(text) {
|
||||
network.send(name, text);
|
||||
}
|
||||
|
||||
element.close = function() {
|
||||
console.log(messages);
|
||||
console.log(messages.parent);
|
||||
messages.parent.removeChild(messages);
|
||||
element.parent.removeChild(element);
|
||||
}
|
||||
element.close = function() {
|
||||
if (messages.parent) {
|
||||
messages.parent.removeChild(messages);
|
||||
}
|
||||
if (element.parent) {
|
||||
element.parent.removeChild(element);
|
||||
}
|
||||
}
|
||||
|
||||
function clicked() {
|
||||
element.show();
|
||||
}
|
||||
function clicked() {
|
||||
element.show();
|
||||
}
|
||||
|
||||
// start hidden
|
||||
element.hide();
|
||||
element.addEventListener("click", clicked);
|
||||
element.getElementsByClassName("content-item")[0].textContent = name;
|
||||
// start hidden
|
||||
element.hide();
|
||||
element.addEventListener("click", clicked);
|
||||
element.getElementsByClassName("content-item")[0].textContent = name;
|
||||
|
||||
document.getElementById("messages-container").appendChild(messages);
|
||||
document.getElementById("messages-container").appendChild(messages);
|
||||
|
||||
return element;
|
||||
return element;
|
||||
}
|
18
wirc.js
18
wirc.js
|
@ -48,14 +48,14 @@ function handleInput(oEvent) {
|
|||
console.log(oEvent);
|
||||
var txt = oEvent.target.value;
|
||||
if (txt.startsWith("/connect ")) {
|
||||
// XXX: should allow tokens with spaces
|
||||
var parts = txt.split(" ");
|
||||
var network = parts[1];
|
||||
var url = parts[2];
|
||||
var authtok = parts[3];
|
||||
var url = parts[1];
|
||||
var authtok = parts.slice(2).join(" ");
|
||||
console.log(url)
|
||||
console.log(authtok)
|
||||
|
||||
networkConnect(network, url, authtok);
|
||||
storedConnections[network] = [url, authtok];
|
||||
networkConnect(url, authtok);
|
||||
storedConnections = [[url, authtok]];
|
||||
chrome.storage.sync.set({"connections": storedConnections});
|
||||
} else {
|
||||
visibleRoom.send(txt);
|
||||
|
@ -86,10 +86,10 @@ function keyPress(oEvent) {
|
|||
function restore(items) {
|
||||
storedConnections = items["connections"];
|
||||
|
||||
for (var network in storedConnections) {
|
||||
var conn = storedConnections[network];
|
||||
for (var i in storedConnections) {
|
||||
var conn = storedConnections[i];
|
||||
|
||||
networkConnect(network, conn[0], conn[1]);
|
||||
networkConnect(conn[0], conn[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue