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,28 @@ |
if (filter.text in keyByFilter) |
return; |
+ if (!("nsIStyleSheetService" in Ci)) |
Wladimir Palant
2015/02/23 19:20:16
Looking up things in Components.interfaces isn't s
Thomas Greiner
2015/03/12 16:00:06
Done.
|
+ { |
+ let domains = filter.domains; |
+ if (domains === null) |
+ { |
+ domains = Object.create(null); |
+ domains[""] = undefined; |
Wladimir Palant
2015/02/23 19:20:16
This should be true, not undefined.
Thomas Greiner
2015/03/12 16:00:06
Done.
|
+ } |
+ |
+ for (let domain in domains) |
+ { |
+ if (!(domain in filtersByDomain)) |
+ { |
+ filtersByDomain[domain] = Object.create(null); |
+ filtersByDomain[domain]._length = 0; |
+ } |
+ |
+ filtersByDomain[domain][filter.text] = filter.isActiveOnDomain(domain); |
Wladimir Palant
2015/02/23 19:20:16
The very point of this functionality is to avoid c
Thomas Greiner
2015/03/12 16:00:06
Done, you're right that it appears to be redundant
|
+ filtersByDomain[domain]._length++; |
Wladimir Palant
2015/02/23 19:20:16
Strictly speaking, _length isn't an invalid domain
Thomas Greiner
2015/03/12 16:00:06
That's true but that might make it difficult to sp
|
+ } |
+ } |
+ |
let key; |
do { |
key = Math.random().toFixed(15).substr(5); |
@@ -164,6 +193,26 @@ |
if (!(filter.text in keyByFilter)) |
return; |
+ if (!("nsIStyleSheetService" in Ci)) |
+ { |
+ let domains = filter.domains; |
+ if (!domains) |
+ { |
+ domains = Object.create(null); |
+ domains[""] = undefined; |
Wladimir Palant
2015/02/23 19:20:16
This should be true, not undefined.
Thomas Greiner
2015/03/12 16:00:06
Done.
|
+ } |
+ |
+ for (let domain in domains) |
+ { |
+ if (domain in filtersByDomain && filter.text in filtersByDomain[domain]) |
+ { |
+ delete filtersByDomain[domain][filter.text]; |
+ if (!--filtersByDomain[domain]._length) |
+ delete filtersByDomain[domain]; |
+ } |
+ } |
+ } |
+ |
let key = keyByFilter[filter.text]; |
delete filterByKey[key]; |
delete keyByFilter[filter.text]; |
@@ -377,16 +426,59 @@ |
*/ |
getSelectorsForDomain: function(/**String*/ domain, /**Boolean*/ specificOnly) |
{ |
Wladimir Palant
2015/02/23 19:20:16
How about an exception here on Firefox, to explain
Thomas Greiner
2015/03/12 16:00:06
Done.
|
- 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)) |
Thomas Greiner
2015/03/12 16:00:06
Done.
|
+ 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) |
Wladimir Palant
2015/02/23 19:20:16
This check seems pointless - if a property exists
Thomas Greiner
2015/03/12 16:00:06
Done.
|
+ { |
+ for (let filterText in filterTexts) |
+ { |
+ if (filterTexts[filterText]) |
+ { |
+ let filter = filterByKey[keyByFilter[filterText]]; |
Wladimir Palant
2015/02/23 19:20:16
let filter = Filter.fromText(filterText);
Thomas Greiner
2015/03/12 16:00:06
Done.
|
+ if (!filter) |
+ continue; |
+ |
+ let selector = filter.selector; |
+ if (!this.getException(selector, docDomain)) |
+ selectors[selectors.length] = selector; |
Wladimir Palant
2015/02/23 19:20:16
You meant using selectors.push(), right?
Thomas Greiner
2015/03/12 16:00:06
This turned out to be about ~3ms faster for each c
|
+ } |
+ } |
+ } |
+ } |
+ |
+ let nextDot = domain.indexOf("."); |
+ if (nextDot < 0) |
+ break; |
+ domain = domain.substr(nextDot + 1); |
} |
Wladimir Palant
2015/02/23 19:20:16
This logic is wrong, we can have a filter ~subdoma
Thomas Greiner
2015/03/12 16:00:06
Indeed, that's true. I added the `ignorableFilters
|
- return result; |
+ |
+ return selectors; |
} |
}; |