From 130d22a754d94a4ea13e2d0bd88973531a7fbe9f Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 30 Apr 2013 11:09:32 -0500 Subject: [PATCH] Add multiple chat filter editor --- www/assets/js/client.js | 69 +++++++++++++++++++++++++++++++++++++++++ www/index.html | 5 +++ 2 files changed, 74 insertions(+) diff --git a/www/assets/js/client.js b/www/assets/js/client.js index bfd307e1..8e7e84b3 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -467,6 +467,75 @@ $("#show_acl").click(function() { } }); +function splitreEntry(str) { + var split = []; + var current = []; + for(var i = 0; i < str.length; i++) { + if(str[i] == "\\" && i+1 < str.length && str[i+1].match(/\s/)) { + current.push(str[i+1]); + i++; + continue; + } + else if(str[i].match(/\s/)) { + split.push(current.join("")); + current = []; + } + else { + current.push(str[i]); + } + } + split.push(current.join("")); + return split; +} + +$("#multifilter").click(function() { + var input = $("#multifiltereditor").val(); + var lines = input.split("\n"); + for(var i = 0; i < lines.length; i++) { + var fields = splitreEntry(lines[i]); + var name = ""; + var regex = ""; + var flags = ""; + var replace = ""; + if(fields.length < 3) { + alert("Minimum of 3 fields per filter: (optional: name), regex, flags, replacement"); + return; + } + else if(fields.length == 3) { + regex = fields[0]; + flags = fields[1]; + replace = fields[2]; + } + else if(fields.length == 4) { + name = fields[0]; + regex = fields[1]; + flags = fields[2]; + replace = fields[3]; + } + else { + alert("Too many paramters: " + fields.join(" ")); + return; + } + try { + new RegExp(regex, flags); + } + catch(e) { + alert("Invalid regex: " + e); + return; + } + socket.emit("chatFilter", { + cmd: "update", + filter: { + name: name, + source: regex, + flags: flags, + replace: replace, + active: true + } + }); + } +}); + function searchLibrary() { socket.emit("searchLibrary", { query: $("#library_query").val() diff --git a/www/index.html b/www/index.html index c9433508..de4771c1 100644 --- a/www/index.html +++ b/www/index.html @@ -247,6 +247,11 @@ +
+

Multiple filters can be added at once below. They should contain 3-4 fields separated by whitespace: (name) regex flags replacement.
If any field contains whitespace, it must be escaped by a backslash, for example "what\ a\ story\ mark"

+ + +