| Index: lib/elemHide.js |
| =================================================================== |
| --- a/lib/elemHide.js |
| +++ b/lib/elemHide.js |
| @@ -59,6 +59,12 @@ |
| let styleURL = null; |
| /** |
| + * Lookup table, blocking filters by domain which they are applied to |
| + * @type Object |
| + */ |
| +let filtersByDomain = Object.create(null); |
| + |
| +/** |
| * Element hiding component |
| * @class |
| */ |
| @@ -105,6 +111,7 @@ |
| keyByFilter = Object.create(null); |
| knownExceptions = Object.create(null); |
| exceptions = Object.create(null); |
| + filtersByDomain = Object.create(null); |
| ElemHide.isDirty = false; |
| ElemHide.unapply(); |
| }, |
| @@ -131,6 +138,24 @@ |
| if (filter.text in keyByFilter) |
| return; |
| + if (!("nsIStyleSheetService" in Ci)) |
| + { |
| + let domains = filter.domains; |
| + if (domains === null) |
| + { |
| + domains = Object.create(null); |
| + domains[""] = undefined; |
| + } |
| + |
| + for (let domain in domains) |
| + { |
| + if (!(domain in filtersByDomain)) |
| + filtersByDomain[domain] = Object.create(null); |
| + |
| + filtersByDomain[domain][filter.text] = filter.isActiveOnDomain(domain); |
| + } |
| + } |
| + |
| let key; |
| do { |
| key = Math.random().toFixed(15).substr(5); |
| @@ -164,6 +189,18 @@ |
| if (!(filter.text in keyByFilter)) |
| return; |
| + if (!("nsIStyleSheetService" in Ci)) |
| + { |
| + for (let domain in filter.domains) |
| + { |
| + if (domain in filtersByDomain && filter.text in filtersByDomain[domain]) |
| + delete filtersByDomain[domain][filter.text]; |
| + |
| + if (!Object.keys(filtersByDomain[domain]).length) |
| + delete filtersByDomain[domain]; |
| + } |
| + } |
| + |
| let key = keyByFilter[filter.text]; |
| delete filterByKey[key]; |
| delete keyByFilter[filter.text]; |
| @@ -377,16 +414,59 @@ |
| */ |
| getSelectorsForDomain: function(/**String*/ domain, /**Boolean*/ specificOnly) |
| { |
| - let result = []; |
| - for (let key in filterByKey) |
| + let selectors = []; |
| + domain = domain.toUpperCase(); |
| + |
| + if (!specificOnly) |
| { |
| - let filter = filterByKey[key]; |
| - if (specificOnly && (!filter.domains || filter.domains[""])) |
| - continue; |
| + let filterTexts = filtersByDomain[""]; |
| + if (filterTexts) |
| + { |
| + for (let filterText in filterTexts) |
| + { |
| + if (filterTexts[filterText]) |
| + { |
| + let filter = filterByKey[keyByFilter[filterText]]; |
| + if (!filter) |
| + continue; |
| + |
| + let selector = filter.selector; |
| + if (filter.isActiveOnDomain(docDomain) && !this.getException(selector, docDomain)) |
| + selectors[selectors.length] = selector; |
| + } |
| + } |
| + } |
| + } |
| - if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain)) |
| - result.push(filter.selector); |
| + while (true) |
| + { |
| + if (domain && domain in filtersByDomain) |
| + { |
| + let filterTexts = filtersByDomain[domain]; |
| + if (filterTexts) |
| + { |
| + for (let filterText in filterTexts) |
| + { |
| + if (filterTexts[filterText]) |
| + { |
| + let filter = filterByKey[keyByFilter[filterText]]; |
| + if (!filter) |
| + continue; |
| + |
| + let selector = filter.selector; |
| + if (!this.getException(selector, docDomain)) |
| + selectors[selectors.length] = selector; |
| + } |
| + } |
| + } |
| + } |
| + |
| + let nextDot = domain.indexOf("."); |
| + if (nextDot < 0) |
| + break; |
| + domain = domain.substr(nextDot + 1); |
| } |
| - return result; |
| + |
| + return selectors; |
| } |
| }; |