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