spongy-client-chrome/wirc.js

107 lines
2.5 KiB
JavaScript
Raw Permalink 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) {
2014-11-07 13:53:50 -07:00
console.log(oEvent);
2014-10-24 15:51:53 -06:00
var txt = oEvent.target.value;
2014-10-23 21:21:54 -06:00
if (txt.startsWith("/connect ")) {
var parts = txt.split(" ");
2015-02-22 20:23:35 -07:00
var url = parts[1];
var authtok = parts.slice(2).join(" ");
console.log(url)
console.log(authtok)
2014-10-23 21:21:54 -06:00
2015-02-22 20:23:35 -07:00
networkConnect(url, authtok);
storedConnections = [[url, authtok]];
2014-10-24 23:25:22 -06:00
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-11-07 13:53:50 -07:00
if (oEvent.keyIdentifier == "Enter") {
handleInput(oEvent);
}
2014-11-01 09:51:48 -06:00
}
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
2015-02-22 20:23:35 -07:00
for (var i in storedConnections) {
var conn = storedConnections[i];
2014-10-24 15:51:53 -06:00
2015-02-22 20:23:35 -07:00
networkConnect(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-11-07 13:53:50 -07: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);