Add chat modifiers and history
This commit is contained in:
parent
d788721b3f
commit
328b38f319
21
channel.js
21
channel.js
|
@ -42,6 +42,11 @@ var Channel = function(name) {
|
|||
pagetitle: "Sync",
|
||||
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.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
|
||||
msg = msg.replace(/</g, "<").replace(/>/g, ">");
|
||||
// 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", {
|
||||
username: username,
|
||||
msg: msg,
|
||||
|
|
4
user.js
4
user.js
|
@ -106,7 +106,9 @@ User.prototype.initCallbacks = function() {
|
|||
}.bind(this));
|
||||
|
||||
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);
|
||||
}
|
||||
}.bind(this));
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
border-left: 0;
|
||||
}
|
||||
|
||||
#messagebuffer div {
|
||||
#messagebuffer div, #messagebuffer code {
|
||||
white-space: pre-wrap; /* css-3 */
|
||||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||
white-space: -pre-wrap; /* Opera 4-6 */
|
||||
|
@ -106,6 +106,10 @@
|
|||
font-size: 18pt;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: Monospace;
|
||||
}
|
||||
|
||||
.poll-notify {
|
||||
color: #0000aa;
|
||||
font-weight: bold;
|
||||
|
|
|
@ -19,6 +19,8 @@ var OPENQUEUE = false;
|
|||
var CHANNELOPTS = {};
|
||||
var GRABBEDLI = null;
|
||||
var OLDINDEX = -1;
|
||||
var CHATHIST = [];
|
||||
var CHATHISTIDX = 0;
|
||||
var uname = readCookie("sync_uname");
|
||||
var pw = readCookie("sync_pw");
|
||||
|
||||
|
@ -186,6 +188,10 @@ $("#chatline").keydown(function(ev) {
|
|||
socket.emit("chatMsg", {
|
||||
msg: $("#chatline").val()
|
||||
});
|
||||
CHATHIST.push($("#chatline").val());
|
||||
if(CHATHIST.length > 10)
|
||||
CHATHIST.shift();
|
||||
CHATHISTIDX = CHATHIST.length;
|
||||
$("#chatline").val("");
|
||||
}
|
||||
else if(ev.keyCode == 9) { // Tab completion
|
||||
|
@ -214,6 +220,27 @@ $("#chatline").keydown(function(ev) {
|
|||
ev.preventDefault();
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue