Ability to add chat filters

This commit is contained in:
calzoneman 2013-06-18 15:59:45 -04:00
parent 6eaa9a45d0
commit b60981c8d8
3 changed files with 78 additions and 5 deletions

View File

@ -114,12 +114,10 @@ Callbacks = {
}, 100);
return;
}
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
tbl.find(".filter-row").remove();
for(var i = 0; i < entries.length; i++) {
var f = entries[i];
var tr = $("<tr/>").appendTo(tbl);
var tr = $("<tr/>").appendTo(tbl).addClass("filter-row");
var remove = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<i/>").addClass("icon-trash").appendTo(remove);

View File

@ -81,4 +81,31 @@
js: $("#jstext").val()
});
});
$("#newfilter_submit").click(function() {
var re = $("#newfilter_regex").val();
var flags = $("#newfilter_flags").val();
try {
new RegExp(re, flags);
}
catch(e) {
makeAlert("Invalid Regex", e, "alert-error")
.insertAfter($("#filteredit form"));
return;
}
socket.emit("updateFilter", {
name: $("#newfilter_name").val(),
source: re,
flags: flags,
replace: $("#newfilter_replace").val(),
filterlinks: $("#newfilter_filterlinks").prop("checked"),
active: true
});
$("#newfilter_name").val("");
$("#newfilter_regex").val("");
$("#newfilter_flags").val("");
$("#newfilter_replace").val("");
});
})();

View File

@ -92,7 +92,7 @@
</div>
<div id="filteredit" class="span12">
<p>Filters will be processed in the order that they are listed here. Click and drag a row to rearrange the order. Click a regex, flags, or replacement field to edit a filter. Changes are automatically saved when you finish editing.</p>
<table class="table table-striped">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Delete</th>
@ -105,6 +105,54 @@
</tr>
</thead>
</table>
<strong>Add Filter</strong>
<form class="form-horizontal" action="javascript:void(0)">
<div class="control-group">
<label class="control-label" for="newfilter_name">
Name
</label>
<div class="controls">
<input type="text" id="newfilter_name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="newfilter_regex">
Regex
</label>
<div class="controls">
<input type="text" id="newfilter_regex">
</div>
</div>
<div class="control-group">
<label class="control-label" for="newfilter_flags">
Flags
</label>
<div class="controls">
<input type="text" id="newfilter_flags" value="g">
</div>
</div>
<div class="control-group">
<label class="control-label" for="newfilter_replace">
Replacement
</label>
<div class="controls">
<input type="text" id="newfilter_replace">
</div>
</div>
<div class="control-group">
<label class="control-label" for="newfilter_filterlinks">
Filter Links
</label>
<div class="controls">
<input type="checkbox" id="newfilter_filterlinks">
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" id="newfilter_submit">New Filter</button>
</div>
</div>
</form>
</div>
<div id="cssedit" class="span12">
<p>Max 20KB. If you need more space, host the file externally and use the External CSS option</p>