Handle #215, re-add multifilter editor

This commit is contained in:
calzoneman 2013-07-30 09:27:13 -04:00
parent fe2985e8dd
commit d9c4c32c6d
2 changed files with 72 additions and 13 deletions

View File

@ -142,4 +142,60 @@
$("#newfilter_flags").val("g");
$("#newfilter_replace").val("");
});
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;
}
$("#multifiltersubmit").click(function () {
var lines = $("#multifiltereditor").val().split("\n");
for(var i in lines) {
var ln = lines[i];
var fields = splitreEntry(ln);
if(fields.length < 3 || fields.length > 4) {
makeAlert("Error on line "+(parseInt(i)+1)+". Format: name regex flags replacement", "alert-error")
.insertBefore($("#multifiltereditor"));
return;
}
var name = "", re = "", f = "", replace = "";
if(fields.length == 3) {
name = fields[0];
re = fields[0];
f = fields[1];
replace = fields[2];
}
else if(fields.length == 4) {
name = fields[0];
re = fields[1];
f = fields[2];
replace = fields[3];
}
socket.emit("updateFilter", {
name: name,
source: re,
flags: f,
replace: replace,
filterlinks: false,
active: true
});
}
});
})();

View File

@ -114,19 +114,6 @@
</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-condensed">
<thead>
<tr>
<th>Delete</th>
<th>Name</th>
<th>Regex</th>
<th>Flags</th>
<th>Replacement</th>
<th>Affects Links</th>
<th>Active</th>
</tr>
</thead>
</table>
<strong>Add Filter</strong>
<form class="form-horizontal" action="javascript:void(0)">
<div class="control-group">
@ -175,6 +162,22 @@
</div>
</div>
</form>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Delete</th>
<th>Name</th>
<th>Regex</th>
<th>Flags</th>
<th>Replacement</th>
<th>Affects Links</th>
<th>Active</th>
</tr>
</thead>
</table>
<p>Multi-Filter Editor (format: name regex flags replacement). Only use this if you know what you are doing</p>
<textarea id="multifiltereditor" class="input-block-level" rows="10"></textarea>
<button class="btn btn-primary" id="multifiltersubmit">Add/Update</button>
</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>