Index: options.js |
=================================================================== |
--- a/options.js |
+++ b/options.js |
@@ -29,6 +29,11 @@ |
this.SpecialSubscription = SpecialSubscription; |
this.DownloadableSubscription = DownloadableSubscription; |
} |
+with(require("filterValidation")) |
+{ |
+ this.parseFilter = parseFilter; |
+ this.parseFilters = parseFilters; |
+} |
var FilterStorage = require("filterStorage").FilterStorage; |
var FilterNotifier = require("filterNotifier").FilterNotifier; |
var Prefs = require("prefs").Prefs; |
@@ -472,12 +477,23 @@ |
{ |
event.preventDefault(); |
- var filterText = Filter.normalize(document.getElementById("newFilter").value); |
- document.getElementById("newFilter").value = ""; |
- if (!filterText) |
+ var element = document.getElementById("newFilter"); |
+ var filter; |
+ |
+ try |
+ { |
+ filter = parseFilter(element.value); |
+ } |
+ catch (error) |
+ { |
+ alert(error); |
return; |
+ } |
- FilterStorage.addFilter(Filter.fromText(filterText)); |
+ if (filter) |
+ FilterStorage.addFilter(filter); |
+ |
+ element.value = ""; |
} |
// Removes currently selected whitelisted domains |
@@ -529,21 +545,25 @@ |
// Imports filters in the raw text box |
function importRawFiltersText() |
{ |
- $("#rawFilters").hide(); |
- var filters = document.getElementById("rawFiltersText").value.split("\n"); |
+ var text = document.getElementById("rawFiltersText").value; |
+ |
+ var add; |
+ try |
+ { |
+ add = parseFilters(text); |
+ } |
+ catch (error) |
+ { |
+ alert(error); |
+ return; |
+ } |
+ |
var seenFilter = {__proto__: null}; |
- for (var i = 0; i < filters.length; i++) |
+ for (var i = 0; i < add.length; i++) |
{ |
- var text = Filter.normalize(filters[i]); |
- if (!text) |
- continue; |
- |
- // Don't import filter list header |
- if (/^\[/.test(text)) |
- continue; |
- |
- FilterStorage.addFilter(Filter.fromText(text)); |
- seenFilter[text] = true; |
+ var filter = add[i]; |
+ FilterStorage.addFilter(filter); |
+ seenFilter[filter.text] = null; |
} |
var remove = []; |
@@ -563,8 +583,11 @@ |
remove.push(filter); |
} |
} |
+ |
for (var i = 0; i < remove.length; i++) |
FilterStorage.removeFilter(remove[i]); |
+ |
+ $("#rawFilters").hide(); |
} |
// Called when user explicitly requests filter list updates |