Add chat modifiers and history

This commit is contained in:
calzoneman 2013-03-29 13:15:46 -05:00
parent d788721b3f
commit 328b38f319
4 changed files with 55 additions and 3 deletions

View File

@ -42,6 +42,11 @@ var Channel = function(name) {
pagetitle: "Sync", pagetitle: "Sync",
customcss: "" customcss: ""
}; };
this.filters = [
[new RegExp("`([^`]+)`", "g"), "<code>$1</code>", true],
[new RegExp("\\*([^\\*]+)\\*", "g"), "<strong>$1</strong>", true],
[new RegExp("_([^_]+)_", "g"), "<em>$1</em>", true]
];
this.ipbans = {}; this.ipbans = {};
this.logger = new Logger.Logger("chanlogs/" + this.name + ".log"); this.logger = new Logger.Logger("chanlogs/" + this.name + ".log");
@ -771,7 +776,21 @@ Channel.prototype.sendMessage = function(username, msg, msgclass) {
// I don"t want HTML from strangers // I don"t want HTML from strangers
msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;"); msg = msg.replace(/</g, "&lt;").replace(/>/g, "&gt;");
// Match URLs // Match URLs
msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/, "<a href=\"$1\" target=\"_blank\">$1</a>"); msg = msg.replace(/(((https?)|(ftp))(:\/\/[0-9a-zA-Z\.]+(:[0-9]+)?[^\s$]+))/g, "<a href=\"$1\" target=\"_blank\">$1</a>");
// Apply other filters
for(var i = 0; i < this.filters.length; i++) {
if(!this.filters[i][2])
continue;
var regex = this.filters[i][0];
var replace = this.filters[i][1];
msg = msg.replace(regex, replace);
}
// Chat modifier - monospace
//msg = msg.replace(/`([^`]+)`/g, "<span class=\"mono\">$1</span>");
// Bold
//msg = msg.replace(/\*\*([^\*]+)\*\*/g, "<strong>$1</strong>");
// Italic
//msg = msg.replace(/\*([^\*]+)\*/g, "<em>$1</em>");
this.sendAll("chatMsg", { this.sendAll("chatMsg", {
username: username, username: username,
msg: msg, msg: msg,

View File

@ -106,7 +106,9 @@ User.prototype.initCallbacks = function() {
}.bind(this)); }.bind(this));
this.socket.on("chatMsg", function(data) { this.socket.on("chatMsg", function(data) {
if(this.name != "" && this.channel != null) { if(this.name != "" && this.channel != null && data.msg != undefined) {
if(data.msg.length > 500)
data.msg = data.msg.substring(0, 500);
this.channel.chatMessage(this, data.msg); this.channel.chatMessage(this, data.msg);
} }
}.bind(this)); }.bind(this));

View File

@ -56,7 +56,7 @@
border-left: 0; border-left: 0;
} }
#messagebuffer div { #messagebuffer div, #messagebuffer code {
white-space: pre-wrap; /* css-3 */ white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */ white-space: -pre-wrap; /* Opera 4-6 */
@ -106,6 +106,10 @@
font-size: 18pt; font-size: 18pt;
} }
.mono {
font-family: Monospace;
}
.poll-notify { .poll-notify {
color: #0000aa; color: #0000aa;
font-weight: bold; font-weight: bold;

View File

@ -19,6 +19,8 @@ var OPENQUEUE = false;
var CHANNELOPTS = {}; var CHANNELOPTS = {};
var GRABBEDLI = null; var GRABBEDLI = null;
var OLDINDEX = -1; var OLDINDEX = -1;
var CHATHIST = [];
var CHATHISTIDX = 0;
var uname = readCookie("sync_uname"); var uname = readCookie("sync_uname");
var pw = readCookie("sync_pw"); var pw = readCookie("sync_pw");
@ -186,6 +188,10 @@ $("#chatline").keydown(function(ev) {
socket.emit("chatMsg", { socket.emit("chatMsg", {
msg: $("#chatline").val() msg: $("#chatline").val()
}); });
CHATHIST.push($("#chatline").val());
if(CHATHIST.length > 10)
CHATHIST.shift();
CHATHISTIDX = CHATHIST.length;
$("#chatline").val(""); $("#chatline").val("");
} }
else if(ev.keyCode == 9) { // Tab completion else if(ev.keyCode == 9) { // Tab completion
@ -214,6 +220,27 @@ $("#chatline").keydown(function(ev) {
ev.preventDefault(); ev.preventDefault();
return false; return false;
} }
else if(ev.keyCode == 38) {
if(CHATHISTIDX == CHATHIST.length) {
CHATHIST.push($("#chatline").val());
}
if(CHATHISTIDX > 0) {
CHATHISTIDX--;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault();
return false;
}
else if(ev.keyCode == 40) {
if(CHATHISTIDX < CHATHIST.length - 1) {
CHATHISTIDX++;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault();
return false;
}
}); });
$("#opt_submit").click(function() { $("#opt_submit").click(function() {