Index: options.js |
=================================================================== |
--- a/options.js |
+++ b/options.js |
@@ -22,6 +22,7 @@ |
{ |
this.Filter = Filter; |
this.WhitelistFilter = WhitelistFilter; |
+ this.InvalidFilter = InvalidFilter; |
} |
with(require("subscriptionClasses")) |
{ |
@@ -473,11 +474,19 @@ |
event.preventDefault(); |
var filterText = Filter.normalize(document.getElementById("newFilter").value); |
+ if (filterText) |
+ { |
kzar
2014/11/18 16:32:10
Seems like the logic here is duplicated from backg
Sebastian Noack
2014/11/18 17:42:55
The only common code is the call to alert(). Note
|
+ var filter = Filter.fromText(filterText, true) |
+ if (filter instanceof InvalidFilter) |
+ { |
+ alert(filter.reason); |
+ return; |
kzar
2014/11/18 16:32:10
IMHO it would be more readable if you omitted the
Sebastian Noack
2014/11/18 17:42:55
Then the code below which clears the field would a
|
+ } |
+ |
+ FilterStorage.addFilter(filter); |
+ } |
+ |
document.getElementById("newFilter").value = ""; |
- if (!filterText) |
- return; |
- |
- FilterStorage.addFilter(Filter.fromText(filterText)); |
} |
// Removes currently selected whitelisted domains |
@@ -529,9 +538,10 @@ |
// Imports filters in the raw text box |
function importRawFiltersText() |
{ |
- $("#rawFilters").hide(); |
var filters = document.getElementById("rawFiltersText").value.split("\n"); |
var seenFilter = {__proto__: null}; |
+ |
+ var add = []; |
for (var i = 0; i < filters.length; i++) |
{ |
var text = Filter.normalize(filters[i]); |
@@ -542,9 +552,18 @@ |
if (/^\[/.test(text)) |
continue; |
Wladimir Palant
2014/11/19 16:03:11
You've removed that logic. People will occasionall
Sebastian Noack
2014/11/20 12:51:19
When I unified the code into a reusable helper fun
|
- FilterStorage.addFilter(Filter.fromText(text)); |
+ var filter = Filter.fromText(text, true); |
kzar
2014/11/18 16:32:10
Again seems like this logic is duplicate of above
|
+ if (filter instanceof InvalidFilter) |
+ { |
+ alert(filter.reason); |
+ return; |
+ } |
Wladimir Palant
2014/11/18 16:35:03
It would probably make sense to have a filter vali
|
+ |
+ add.push(filter); |
seenFilter[text] = true; |
} |
+ for (var i = 0; i < add.length; i++) |
+ FilterStorage.addFilter(add[i]); |
var remove = []; |
for (var i = 0; i < FilterStorage.subscriptions.length; i++) |
@@ -565,6 +584,8 @@ |
} |
for (var i = 0; i < remove.length; i++) |
FilterStorage.removeFilter(remove[i]); |
+ |
+ $("#rawFilters").hide(); |
} |
// Called when user explicitly requests filter list updates |