Index: lib/elemHide.js |
diff --git a/lib/elemHide.js b/lib/elemHide.js |
index d8d2711046443f291d87fbc1f390200e10aa6049..bcf813d90fb0b5799d0c7be78959f17c74782d38 100644 |
--- a/lib/elemHide.js |
+++ b/lib/elemHide.js |
@@ -15,6 +15,8 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
+"use strict"; |
+ |
/** |
* @fileOverview Element hiding implementation. |
*/ |
@@ -25,71 +27,70 @@ let {FilterNotifier} = require("filterNotifier"); |
/** |
* Lookup table, filters by their associated key |
- * @type Object |
+ * @type {Object} |
*/ |
-var filterByKey = []; |
+let filterByKey = []; |
/** |
* Lookup table, keys of the filters by filter text |
- * @type Object |
+ * @type {Object} |
*/ |
-var keyByFilter = Object.create(null); |
+let keyByFilter = Object.create(null); |
/** |
* Nested lookup table, filter (or false if inactive) by filter key by domain. |
* (Only contains filters that aren't unconditionally matched for all domains.) |
- * @type Object |
+ * @type {Object} |
*/ |
-var filtersByDomain = Object.create(null); |
+let filtersByDomain = Object.create(null); |
/** |
* Lookup table, filter key by selector. (Only used for selectors that are |
* unconditionally matched for all domains.) |
*/ |
-var filterKeyBySelector = Object.create(null); |
+let filterKeyBySelector = Object.create(null); |
/** |
* This array caches the keys of filterKeyBySelector table (selectors which |
* unconditionally apply on all domains). It will be null if the cache needs to |
* be rebuilt. |
*/ |
-var unconditionalSelectors = null; |
+let unconditionalSelectors = null; |
/** |
* This array caches the values of filterKeyBySelector table (filterIds for |
* selectors which unconditionally apply on all domains). It will be null if the |
* cache needs to be rebuilt. |
*/ |
-var unconditionalFilterKeys = null; |
+let unconditionalFilterKeys = null; |
/** |
* Object to be used instead when a filter has a blank domains property. |
*/ |
-var defaultDomains = Object.create(null); |
+let defaultDomains = Object.create(null); |
defaultDomains[""] = true; |
/** |
* Lookup table, keys are known element hiding exceptions |
- * @type Object |
+ * @type {Object} |
*/ |
-var knownExceptions = Object.create(null); |
+let knownExceptions = Object.create(null); |
/** |
* Lookup table, lists of element hiding exceptions by selector |
- * @type Object |
+ * @type {Object} |
*/ |
-var exceptions = Object.create(null); |
+let exceptions = Object.create(null); |
/** |
* Container for element hiding filters |
* @class |
*/ |
-var ElemHide = exports.ElemHide = |
-{ |
+let ElemHide = exports.ElemHide = { |
/** |
* Removes all known filters |
*/ |
- clear: function() |
+ clear() |
{ |
filterByKey = []; |
keyByFilter = Object.create(null); |
@@ -101,7 +102,7 @@ var ElemHide = exports.ElemHide = |
FilterNotifier.emit("elemhideupdate"); |
}, |
- _addToFiltersByDomain: function(key, filter) |
+ _addToFiltersByDomain(key, filter) |
{ |
let domains = filter.domains || defaultDomains; |
for (let domain in domains) |
@@ -121,14 +122,14 @@ var ElemHide = exports.ElemHide = |
* Add a new element hiding filter |
* @param {ElemHideFilter} filter |
*/ |
- add: function(filter) |
+ add(filter) |
{ |
if (filter instanceof ElemHideException) |
{ |
if (filter.text in knownExceptions) |
return; |
- let selector = filter.selector; |
+ let {selector} = filter; |
if (!(selector in exceptions)) |
exceptions[selector] = []; |
exceptions[selector].push(filter); |
@@ -170,7 +171,7 @@ var ElemHide = exports.ElemHide = |
FilterNotifier.emit("elemhideupdate"); |
}, |
- _removeFilterKey: function(key, filter) |
+ _removeFilterKey(key, filter) |
{ |
if (filterKeyBySelector[filter.selector] == key) |
{ |
@@ -194,7 +195,7 @@ var ElemHide = exports.ElemHide = |
* Removes an element hiding filter |
* @param {ElemHideFilter} filter |
*/ |
- remove: function(filter) |
+ remove(filter) |
{ |
if (filter instanceof ElemHideException) |
{ |
@@ -224,24 +225,31 @@ var ElemHide = exports.ElemHide = |
/** |
* Checks whether an exception rule is registered for a filter on a particular |
* domain. |
+ * @param {Filter} filter |
+ * @param {String} docDomain |
+ * @return {ElemHideException} |
*/ |
- getException: function(/**Filter*/ filter, /**String*/ docDomain) /**ElemHideException*/ |
+ getException(filter, docDomain) |
{ |
if (!(filter.selector in exceptions)) |
return null; |
let list = exceptions[filter.selector]; |
for (let i = list.length - 1; i >= 0; i--) |
+ { |
if (list[i].isActiveOnDomain(docDomain)) |
return list[i]; |
+ } |
return null; |
}, |
/** |
* Retrieves an element hiding filter by the corresponding protocol key |
+ * @param {Number} key |
+ * @return {Filter} |
*/ |
- getFilterByKey: function(/**Number*/ key) /**Filter*/ |
+ getFilterByKey(key) |
{ |
return (key in filterByKey ? filterByKey[key] : null); |
}, |
@@ -253,13 +261,13 @@ var ElemHide = exports.ElemHide = |
* with the keys being selectors and values the corresponding filter keys. |
* @returns {Map.<String,Map<String,String>>} |
*/ |
- getSelectors: function() |
+ getSelectors() |
{ |
let domains = new Map(); |
for (let key in filterByKey) |
{ |
let filter = filterByKey[key]; |
- let selector = filter.selector; |
+ let {selector} = filter; |
Sebastian Noack
2017/02/20 13:14:51
Perhaps just inline filter.selector, in the two oc
kzar
2017/02/21 06:13:58
Seems like kind of an unrelated change, would rath
Sebastian Noack
2017/02/21 09:19:30
Well, it's not unrelated, because in order to make
Sebastian Noack
2017/02/21 09:20:13
s/it's not related/it's related/
kzar
2017/02/21 10:37:00
Done.
|
if (!selector) |
continue; |
@@ -277,7 +285,7 @@ var ElemHide = exports.ElemHide = |
* Returns a list of selectors that apply on each website unconditionally. |
* @returns {String[]} |
*/ |
- getUnconditionalSelectors: function() |
+ getUnconditionalSelectors() |
{ |
if (!unconditionalSelectors) |
unconditionalSelectors = Object.keys(filterKeyBySelector); |
@@ -289,7 +297,7 @@ var ElemHide = exports.ElemHide = |
* without exception. |
* @returns {Number[]} |
*/ |
- getUnconditionalFilterKeys: function() |
+ getUnconditionalFilterKeys() |
{ |
if (!unconditionalFilterKeys) |
{ |
@@ -335,7 +343,7 @@ var ElemHide = exports.ElemHide = |
* List of selectors or an array with two elements (list of selectors and |
* list of corresponding keys) if provideFilterKeys is true. |
*/ |
- getSelectorsForDomain: function(domain, criteria, provideFilterKeys) |
+ getSelectorsForDomain(domain, criteria, provideFilterKeys) |
{ |
let filterKeys = []; |
let selectors = []; |
@@ -352,6 +360,7 @@ var ElemHide = exports.ElemHide = |
let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); |
let seenFilters = Object.create(null); |
let currentDomain = domain ? domain.toUpperCase() : ""; |
+ /* eslint-disable no-constant-condition */ |
Sebastian Noack
2017/02/20 13:14:51
Ugh. Can we please change esling-config-eyeo, conf
kzar
2017/02/21 06:13:58
Done. https://codereview.adblockplus.org/29376668/
|
while (true) |
{ |
if (specificOnly && currentDomain == "") |
@@ -382,10 +391,10 @@ var ElemHide = exports.ElemHide = |
let nextDot = currentDomain.indexOf("."); |
currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
} |
+ /* eslint-enable no-constant-condition */ |
if (provideFilterKeys) |
return [selectors, filterKeys]; |
- else |
- return selectors; |
+ return selectors; |
} |
}; |