| Index: lib/elemHide.js |
| diff --git a/lib/elemHide.js b/lib/elemHide.js |
| index ee309d1d4a823b798804f41693dc97c22236d598..5ba0be1508670fce8003777a5ec2430a6b232fc5 100644 |
| --- a/lib/elemHide.js |
| +++ b/lib/elemHide.js |
| @@ -55,6 +55,12 @@ var usingGetSelectorsForDomain = !("nsIStyleSheetService" in Ci); |
| var filtersByDomain = Object.create(null); |
| /** |
| + * Lookup table, count of filter exceptions by domain. |
| + * @type Object |
| + */ |
| +var exceptionCountByDomain = Object.create(null); |
| + |
| +/** |
| * Lookup table, filters by selector. (Only contains filters that have a |
| * selector that is unconditionally matched for all domains.) |
| */ |
| @@ -135,6 +141,7 @@ var ElemHide = exports.ElemHide = |
| keyByFilter = Object.create(null); |
| filtersByDomain = Object.create(null); |
| filtersBySelector = Object.create(null); |
| + exceptionCountByDomain = Object.create(null); |
| unconditionalSelectors = null; |
| knownExceptions = Object.create(null); |
| exceptions = Object.create(null); |
| @@ -153,9 +160,17 @@ var ElemHide = exports.ElemHide = |
| filters = filtersByDomain[domain] = Object.create(null); |
| if (domains[domain]) |
| + { |
| filters[key] = filter; |
| + } |
| else |
| + { |
| filters[key] = false; |
| + if (domain in exceptionCountByDomain) |
| + exceptionCountByDomain[domain] += 1; |
| + else |
| + exceptionCountByDomain[domain] = 1; |
| + } |
| } |
| }, |
| @@ -177,6 +192,15 @@ var ElemHide = exports.ElemHide = |
| if (usingGetSelectorsForDomain) |
| { |
| + let domains = filter.domains || defaultDomains; |
| + for (let domain in domains) |
| + { |
| + if (domain in exceptionCountByDomain) |
| + exceptionCountByDomain[domain] += 1; |
| + else |
| + exceptionCountByDomain[domain] = 1; |
| + } |
| + |
| // If this is the first exception for a previously unconditionally |
| // applied element hiding selector we need to take care to update the |
| // lookups. |
| @@ -256,6 +280,16 @@ var ElemHide = exports.ElemHide = |
| if (usingGetSelectorsForDomain) |
| { |
| + let domains = filter.domains || defaultDomains; |
| + for (let domain in domains) |
| + { |
| + let count = exceptionCountByDomain[domain]; |
| + if (count > 1) |
| + exceptionCountByDomain[domain] -= 1; |
| + else if (count) |
|
Sebastian Noack
2016/05/26 11:46:43
It seems the condition to check for non-zero count
|
| + delete exceptionCountByDomain[domain]; |
| + } |
| + |
| let filters = filtersBySelector[filter.selector]; |
| if (filters) |
| { |
| @@ -501,12 +535,31 @@ var ElemHide = exports.ElemHide = |
| unconditionalSelectors = Object.keys(filtersBySelector); |
| let selectors = specificOnly ? [] : unconditionalSelectors.slice(); |
| + let anyExceptions = false; |
| + |
| let seenFilters = Object.create(null); |
| let currentDomain = domain ? domain.toUpperCase() : ""; |
| while (true) |
| { |
| - if (specificOnly && currentDomain == "") |
| - break; |
| + if (currentDomain == "") |
| + { |
| + if (specificOnly) |
| + break; |
| + |
| + // For domains with no exceptions we can add all generic rules |
| + if (!anyExceptions) |
| + { |
| + let filters = filtersByDomain[""]; |
| + for (let filterKey in filters) |
| + { |
| + let filter = filters[filterKey]; |
| + if (filter) |
|
Sebastian Noack
2016/05/26 11:46:43
Just for my understanding, what is the scenario wh
|
| + selectors.push(filters[filterKey].selector); |
|
Sebastian Noack
2016/05/26 11:46:43
Use the "filter" variable here?
|
| + } |
| + break; |
| + } |
| + } |
| + anyExceptions = anyExceptions || exceptionCountByDomain[currentDomain]; |
|
Sebastian Noack
2016/05/26 11:46:43
I think it's preferable to write it like this:
i
|
| let filters = filtersByDomain[currentDomain]; |
| if (filters) |