Index: lib/elemHide.js |
=================================================================== |
--- a/lib/elemHide.js |
+++ b/lib/elemHide.js |
@@ -120,19 +120,20 @@ |
* Add a new element hiding filter |
* @param {ElemHideBase} filter |
*/ |
add(filter) |
{ |
if (knownFilters.has(filter)) |
return; |
+ let {selector} = filter; |
+ |
if (filter instanceof ElemHideException) |
{ |
- let {selector} = filter; |
let list = exceptions.get(selector); |
if (list) |
list.push(filter); |
else |
exceptions.set(selector, [filter]); |
// If this is the first exception for a previously unconditionally |
// applied element hiding selector we need to take care to update the |
@@ -140,20 +141,20 @@ |
let unconditionalFilterForSelector = filterBySelector.get(selector); |
if (unconditionalFilterForSelector) |
{ |
addToFiltersByDomain(unconditionalFilterForSelector); |
filterBySelector.delete(selector); |
unconditionalSelectors = null; |
} |
} |
- else if (!(filter.domains || exceptions.has(filter.selector))) |
+ else if (!(filter.domains || exceptions.has(selector))) |
{ |
// The new filter's selector is unconditionally applied to all domains |
- filterBySelector.set(filter.selector, filter); |
+ filterBySelector.set(selector, filter); |
unconditionalSelectors = null; |
} |
else |
{ |
// The new filter's selector only applies to some domains |
addToFiltersByDomain(filter); |
} |
@@ -165,28 +166,30 @@ |
* Removes an element hiding filter |
* @param {ElemHideBase} filter |
*/ |
remove(filter) |
{ |
if (!knownFilters.has(filter)) |
return; |
+ let {selector} = filter; |
+ |
// Whitelisting filters |
if (filter instanceof ElemHideException) |
{ |
- let list = exceptions.get(filter.selector); |
+ let list = exceptions.get(selector); |
let index = list.indexOf(filter); |
if (index >= 0) |
list.splice(index, 1); |
} |
// Unconditially applied element hiding filters |
- else if (filterBySelector.get(filter.selector) == filter) |
+ else if (filterBySelector.get(selector) == filter) |
{ |
- filterBySelector.delete(filter.selector); |
+ filterBySelector.delete(selector); |
unconditionalSelectors = null; |
} |
// Conditionally applied element hiding filters |
else |
{ |
let domains = filter.domains || defaultDomains; |
for (let domain of domains.keys()) |
{ |
@@ -196,25 +199,25 @@ |
} |
} |
knownFilters.delete(filter); |
FilterNotifier.emit("elemhideupdate"); |
}, |
/** |
- * Checks whether an exception rule is registered for a filter on a particular |
- * domain. |
- * @param {Filter} filter |
+ * Checks whether an exception rule is registered for a selector on a |
+ * particular domain. |
+ * @param {string} selector |
* @param {?string} docDomain |
* @return {?ElemHideException} |
*/ |
- getException(filter, docDomain) |
+ getException(selector, docDomain) |
{ |
- let list = exceptions.get(filter.selector); |
+ let list = exceptions.get(selector); |
if (!list) |
return null; |
for (let i = list.length - 1; i >= 0; i--) |
{ |
if (list[i].isActiveOnDomain(docDomain)) |
return list[i]; |
} |
@@ -247,20 +250,24 @@ |
if (filters) |
{ |
for (let [filter, isIncluded] of filters) |
{ |
if (!isIncluded) |
{ |
excluded.add(filter); |
} |
- else if ((excluded.size == 0 || !excluded.has(filter)) && |
- !this.getException(filter, domain)) |
+ else |
{ |
- selectors.push(filter.selector); |
+ let {selector} = filter; |
+ if ((excluded.size == 0 || !excluded.has(filter)) && |
+ !this.getException(selector, domain)) |
+ { |
+ selectors.push(selector); |
+ } |
} |
} |
} |
if (currentDomain == "") |
break; |
let nextDot = currentDomain.indexOf("."); |