spongy/app/wirc.js

103 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-07-23 21:15:04 -06:00
var msgRe = /([^ ]+) (<[^>]+>) (.*)/;
var kibozeRe = /[Nn]eal/;
var urlRe = /[a-z]+:\/\/[^ ]*/;
var nick = "Mme. M";
2014-07-24 10:34:02 -06:00
2014-10-23 21:21:54 -06:00
if (String.prototype.startsWith == null) {
String.prototype.startsWith = function(needle) {
return this.lastIndexOf(needle, 0) == 0;
}
}
2014-10-24 15:51:53 -06:00
function getTemplate(className) {
2014-10-24 23:25:22 -06:00
return templates.getElementsByClassName(className)[0].cloneNode(true);
2014-10-24 15:51:53 -06:00
}
2014-07-24 10:34:02 -06:00
function isinView(oObject) {
return (oObject.offsetParent.clientHeight <= oObject.offsetTop);
}
2014-07-23 21:15:04 -06:00
function addMessagePart(p, className, text) {
var e = document.createElement("span");
e.className = className;
e.appendChild(document.createTextNode(text));
p.appendChild(e);
p.appendChild(document.createTextNode(" "));
}
2014-07-24 10:56:37 -06:00
function focus(e) {
var pct = 1;
var timeout;
2014-10-24 15:51:53 -06:00
selectForum(e.parentNode);
2014-07-24 10:56:37 -06:00
e.scrollIntoView(false);
e.style.backgroundColor = "yellow";
2014-10-24 15:51:53 -06:00
2014-07-24 10:56:37 -06:00
timeout = setInterval(function() {
pct = pct - 0.1;
e.style.backgroundColor = "rgba(255, 255, 0, " + pct + ")";
if (pct <= 0) {
2014-10-24 15:51:53 -06:00
e.style.backgroundColor = "inherit";
2014-07-24 10:56:37 -06:00
clearInterval(timeout);
}
}, 50)
}
2014-07-23 21:15:04 -06:00
2014-10-24 15:51:53 -06:00
function handleInput(oEvent) {
var txt = oEvent.target.value;
2014-10-23 21:21:54 -06:00
if (txt.startsWith("/connect ")) {
// XXX: should allow tokens with spaces
var parts = txt.split(" ");
2014-10-24 23:25:22 -06:00
var network = parts[1];
var url = parts[2];
var authtok = parts[3];
2014-10-23 21:21:54 -06:00
2014-10-24 23:25:22 -06:00
connect(network, url, authtok);
storedConnections[network] = [url, authtok];
chrome.storage.sync.set({"connections": storedConnections});
2014-10-24 12:29:38 -06:00
} else {
visibleRoom.send(txt);
2014-10-23 21:21:54 -06:00
}
2014-10-24 15:51:53 -06:00
oEvent.target.value = "";
2014-07-23 21:15:04 -06:00
return false;
}
2014-10-31 16:09:52 -06:00
function hideChannels(oEvent) {
var lhs = document.getElementById("rooms-and-nicks");
if (lhs.classList.contains("hidden")) {
lhs.classList.remove("hidden");
} else {
lhs.classList.add("hidden");
}
}
2014-11-01 09:51:48 -06:00
function keyPress(oEvent) {
document.getElementById("input").focus();
}
2014-10-24 12:29:38 -06:00
function restore(items) {
2014-10-24 23:25:22 -06:00
storedConnections = items["connections"];
2014-10-24 15:51:53 -06:00
2014-10-24 23:25:22 -06:00
for (var network in storedConnections) {
var conn = storedConnections[network];
2014-10-24 15:51:53 -06:00
networkConnect(network, conn[0], conn[1]);
2014-10-24 15:51:53 -06:00
}
2014-10-23 21:21:54 -06:00
}
function init() {
2014-10-24 23:25:22 -06:00
chrome.storage.sync.get(["connections"], restore);
2014-10-24 15:51:53 -06:00
document.getElementById("input").addEventListener("change", handleInput);
2014-10-31 16:09:52 -06:00
document.getElementById("hide-channels").addEventListener("click", hideChannels);
2014-11-01 09:51:48 -06:00
window.addEventListener("keypress", keyPress);
2014-10-24 15:51:53 -06:00
2014-10-24 23:25:22 -06:00
templates = document.getElementById("templates");
rooms = document.getElementById("rooms-container").getElementsByClassName("rooms")[0];
2014-07-23 21:15:04 -06:00
}
2014-10-24 15:51:53 -06:00
window.addEventListener("load", init);