| Index: lib/elemHideExceptions.js |
| =================================================================== |
| --- a/lib/elemHideExceptions.js |
| +++ b/lib/elemHideExceptions.js |
| @@ -26,16 +26,22 @@ |
| /** |
| * Lookup table, lists of element hiding exceptions by selector |
| * @type {Map.<string,ElemHideException[]>} |
| */ |
| let exceptions = new Map(); |
| /** |
| + * Set containing all known domains |
| + * @type {Set.<string>} |
| + */ |
| +let knownDomains = new Set(); |
| + |
| +/** |
| * Set containing known element exceptions |
| * @type {Set.<ElemHideException>} |
| */ |
| let knownExceptions = new Set(); |
| /** |
| * Container for element hiding exceptions |
| * @class |
| @@ -56,17 +62,30 @@ |
| * Add a new element hiding exception |
| * @param {ElemHideException} exception |
| */ |
| add(exception) |
| { |
| if (knownExceptions.has(exception)) |
| return; |
| - let {selector} = exception; |
| + let {domains, selector} = exception; |
| + |
| + if (domains) |
| + { |
| + for (let domain of domains.keys()) |
| + { |
| + // Note: Once a domain is known it never becomes unknown, even when all |
| + // the filters containing that domain are removed. This is a best-case |
| + // optimization. |
| + if (domain != "") |
| + knownDomains.add(domain); |
| + } |
| + } |
| + |
| let list = exceptions.get(selector); |
| if (list) |
| list.push(exception); |
| else |
| exceptions.set(selector, [exception]); |
| knownExceptions.add(exception); |
| @@ -92,16 +111,26 @@ |
| knownExceptions.delete(exception); |
| this.emit("removed", exception); |
| filterNotifier.emit("elemhideupdate"); |
| }, |
| /** |
| + * Checks whether a given domain is known. |
| + * @param {string} domain |
| + * @returns {boolean} |
| + */ |
| + isKnownDomain(domain) |
| + { |
| + return knownDomains.has(domain); |
| + }, |
| + |
| + /** |
| * Checks whether any exception rules are registered for a selector |
| * @param {string} selector |
| * @returns {boolean} |
| */ |
| hasExceptions(selector) |
| { |
| return exceptions.has(selector); |
| }, |