Can send text now
This commit is contained in:
parent
d48dd8325a
commit
f96c870be3
|
@ -31,8 +31,29 @@ function Server(network, baseURL, authtok, messageHandler) {
|
||||||
messageHandler(timestamp, null, "ERROR", null, null, [], null);
|
messageHandler(timestamp, null, "ERROR", null, null, [], null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function send(target, text) {
|
||||||
|
function handleError(oEvent) {
|
||||||
|
console.log("XXX: That didn't work out.", target, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var form = new FormData();
|
||||||
|
form.append("type", "command");
|
||||||
|
form.append("auth", authtok);
|
||||||
|
form.append("network", network);
|
||||||
|
form.append("target", target);
|
||||||
|
form.append("text", text);
|
||||||
|
console.log(form);
|
||||||
|
|
||||||
|
var oReq = new XMLHttpRequest();
|
||||||
|
oReq.addEventListener("error", handleError);
|
||||||
|
oReq.open("POST", baseURL, true);
|
||||||
|
oReq.send(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.send = send;
|
||||||
|
|
||||||
var pullURL = baseURL + "?network=" + encodeURIComponent(network) + "&auth=" + encodeURIComponent(authtok);
|
var pullURL = baseURL + "?network=" + encodeURIComponent(network) + "&auth=" + encodeURIComponent(authtok);
|
||||||
this.eventSource = new EventSource(pullURL);
|
var eventSource = new EventSource(pullURL);
|
||||||
this.eventSource.addEventListener("message", handleEventSourceMessage);
|
eventSource.addEventListener("message", handleEventSourceMessage);
|
||||||
this.eventSource.addEventListener("error", handleEventSourceError);
|
eventSource.addEventListener("error", handleEventSourceError);
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,7 +366,7 @@ ul {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message .sender {
|
.message .source {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
margin-left: -5px;
|
margin-left: -5px;
|
||||||
|
@ -376,11 +376,11 @@ ul {
|
||||||
cursor: text;
|
cursor: text;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message .sender.empty {
|
.message .source.empty {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message .text {
|
.message .content {
|
||||||
display: inline;
|
display: inline;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
cursor: text;
|
cursor: text;
|
||||||
|
|
39
app/wirc.js
39
app/wirc.js
|
@ -7,6 +7,7 @@ var nick = "Mme. M";
|
||||||
// XXX: get rid of this
|
// XXX: get rid of this
|
||||||
var scrollbackLength = 500;
|
var scrollbackLength = 500;
|
||||||
var current;
|
var current;
|
||||||
|
var target;
|
||||||
|
|
||||||
if (String.prototype.startsWith == null) {
|
if (String.prototype.startsWith == null) {
|
||||||
String.prototype.startsWith = function(needle) {
|
String.prototype.startsWith = function(needle) {
|
||||||
|
@ -14,6 +15,16 @@ if (String.prototype.startsWith == null) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function djbhash(a) {
|
||||||
|
var r = 5381;
|
||||||
|
|
||||||
|
for (var i = 0; i < a.length; i += 1) {
|
||||||
|
r = (((r << 5) + r) + a.charCodeAt(i)) & 0xffff;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getTemplate(className) {
|
function getTemplate(className) {
|
||||||
return templates.getElementsByClassName(className)[0].cloneNode(true);
|
return templates.getElementsByClassName(className)[0].cloneNode(true);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +42,7 @@ function selectForum(room) {
|
||||||
|
|
||||||
|
|
||||||
current = room;
|
current = room;
|
||||||
|
target = room.target;
|
||||||
room.classList.add("selected");
|
room.classList.add("selected");
|
||||||
room.messages.style.display = "block";
|
room.messages.style.display = "block";
|
||||||
|
|
||||||
|
@ -54,6 +66,7 @@ function getForumElement(forum) {
|
||||||
fe.room = room;
|
fe.room = room;
|
||||||
|
|
||||||
room.messages = fe;
|
room.messages = fe;
|
||||||
|
room.target = forum;
|
||||||
// XXX: split out into non-anon function
|
// XXX: split out into non-anon function
|
||||||
room.addEventListener("click", function() {selectForum(room)});
|
room.addEventListener("click", function() {selectForum(room)});
|
||||||
|
|
||||||
|
@ -133,14 +146,24 @@ function addMessage(timestamp, fullSender, command, sender, forum, args, msg) {
|
||||||
var forumElement = getForumElement(forum);
|
var forumElement = getForumElement(forum);
|
||||||
var msge = getTemplate("message");
|
var msge = getTemplate("message");
|
||||||
|
|
||||||
|
msge.classList.add("update");
|
||||||
|
msge.classList.add("privmsg");
|
||||||
|
|
||||||
|
if (sender == ".") {
|
||||||
|
msge.classList.add("self");
|
||||||
|
}
|
||||||
|
|
||||||
console.log(timestamp, msg);
|
console.log(timestamp, msg);
|
||||||
|
|
||||||
msge.getElementsByClassName("timestamp")[0].textContent = timestamp.toLocaleTimeString();
|
msge.getElementsByClassName("timestamp")[0].textContent = timestamp.toLocaleTimeString();
|
||||||
var sourcee = msge.getElementsByClassName("source")[0];
|
var sourcee = msge.getElementsByClassName("source")[0];
|
||||||
var contente = msge.getElementsByClassName("content")[0];
|
var contente = msge.getElementsByClassName("content")[0];
|
||||||
|
|
||||||
|
var senderhash = djbhash(sender) % 30;
|
||||||
|
sourcee.setAttribute("colornumber", senderhash)
|
||||||
|
|
||||||
|
|
||||||
sourcee.textContent = sender;
|
sourcee.textContent = sender;
|
||||||
contente.textContent = msg;
|
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "PING":
|
case "PING":
|
||||||
|
@ -148,6 +171,7 @@ function addMessage(timestamp, fullSender, command, sender, forum, args, msg) {
|
||||||
return;
|
return;
|
||||||
case "PRIVMSG":
|
case "PRIVMSG":
|
||||||
case "NOTICE":
|
case "NOTICE":
|
||||||
|
addText(contente, msg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
contente.textContent = command + " " + args + " " + msg;
|
contente.textContent = command + " " + args + " " + msg;
|
||||||
|
@ -162,11 +186,6 @@ function addMessage(timestamp, fullSender, command, sender, forum, args, msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleInput(oEvent) {
|
function handleInput(oEvent) {
|
||||||
console.log(oEvent);
|
|
||||||
var oReq = new XMLHttpRequest();
|
|
||||||
function reqListener() {
|
|
||||||
}
|
|
||||||
|
|
||||||
var txt = oEvent.target.value;
|
var txt = oEvent.target.value;
|
||||||
if (txt.startsWith("/connect ")) {
|
if (txt.startsWith("/connect ")) {
|
||||||
// XXX: should allow tokens with spaces
|
// XXX: should allow tokens with spaces
|
||||||
|
@ -179,9 +198,7 @@ function handleInput(oEvent) {
|
||||||
storedConnections[network] = [url, authtok];
|
storedConnections[network] = [url, authtok];
|
||||||
chrome.storage.sync.set({"connections": storedConnections});
|
chrome.storage.sync.set({"connections": storedConnections});
|
||||||
} else {
|
} else {
|
||||||
oReq.onload = reqListener;
|
server.send(target, txt);
|
||||||
oReq.open("POST", window.postURL, true);
|
|
||||||
oReq.send(new FormData(event.target));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oEvent.target.value = "";
|
oEvent.target.value = "";
|
||||||
|
@ -189,6 +206,7 @@ function handleInput(oEvent) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var server;
|
||||||
var activeNetworks = {};
|
var activeNetworks = {};
|
||||||
var storedConnections = {};
|
var storedConnections = {};
|
||||||
|
|
||||||
|
@ -210,6 +228,9 @@ function connect(network, url, authtok) {
|
||||||
newServer.content.textContent = network;
|
newServer.content.textContent = network;
|
||||||
|
|
||||||
activeNetworks[network] = newServer;
|
activeNetworks[network] = newServer;
|
||||||
|
|
||||||
|
// XXX: this should be bound to the element
|
||||||
|
server = newServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue