| Index: lib/elemHide.js |
| diff --git a/lib/elemHide.js b/lib/elemHide.js |
| index d8d2711046443f291d87fbc1f390200e10aa6049..ec53c3829953b450ae42b27f2cae1f54579c4701 100644 |
| --- a/lib/elemHide.js |
| +++ b/lib/elemHide.js |
| @@ -15,81 +15,81 @@ |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| +"use strict"; |
| + |
| /** |
| * @fileOverview Element hiding implementation. |
| */ |
| -let {Utils} = require("utils"); |
| -let {ElemHideException} = require("filterClasses"); |
| -let {FilterNotifier} = require("filterNotifier"); |
| +const {ElemHideException} = require("filterClasses"); |
| +const {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 +101,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 +121,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 +170,7 @@ var ElemHide = exports.ElemHide = |
| FilterNotifier.emit("elemhideupdate"); |
| }, |
| - _removeFilterKey: function(key, filter) |
| + _removeFilterKey(key, filter) |
| { |
| if (filterKeyBySelector[filter.selector] == key) |
| { |
| @@ -194,7 +194,7 @@ var ElemHide = exports.ElemHide = |
| * Removes an element hiding filter |
| * @param {ElemHideFilter} filter |
| */ |
| - remove: function(filter) |
| + remove(filter) |
| { |
| if (filter instanceof ElemHideException) |
| { |
| @@ -224,24 +224,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,21 +260,20 @@ 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; |
| - if (!selector) |
| + if (!filter.selector) |
| continue; |
| let domain = filter.selectorDomain || ""; |
| if (!domains.has(domain)) |
| domains.set(domain, new Map()); |
| - domains.get(domain).set(selector, key); |
| + domains.get(domain).set(filter.selector, key); |
| } |
| return domains; |
| @@ -275,9 +281,9 @@ var ElemHide = exports.ElemHide = |
| /** |
| * Returns a list of selectors that apply on each website unconditionally. |
| - * @returns {String[]} |
| + * @returns {string[]} |
| */ |
| - getUnconditionalSelectors: function() |
| + getUnconditionalSelectors() |
| { |
| if (!unconditionalSelectors) |
| unconditionalSelectors = Object.keys(filterKeyBySelector); |
| @@ -287,9 +293,9 @@ var ElemHide = exports.ElemHide = |
| /** |
| * Returns a list of filter keys for selectors which apply to all websites |
| * without exception. |
| - * @returns {Number[]} |
| + * @returns {number[]} |
| */ |
| - getUnconditionalFilterKeys: function() |
| + getUnconditionalFilterKeys() |
| { |
| if (!unconditionalFilterKeys) |
| { |
| @@ -324,18 +330,18 @@ var ElemHide = exports.ElemHide = |
| * Determines from the current filter list which selectors should be applied |
| * on a particular host name. Optionally returns the corresponding filter |
| * keys. |
| - * @param {String} domain |
| - * @param {Number} [criteria] |
| + * @param {string} domain |
| + * @param {number} [criteria] |
| * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or |
| * ElemHide.SPECIFIC_ONLY. |
| - * @param {Boolean} [provideFilterKeys] |
| + * @param {boolean} [provideFilterKeys] |
| * If true, the function will return a list of corresponding filter keys in |
| * addition to selectors. |
| * @returns {string[]|Array.<string[]>} |
| * 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 = []; |
| @@ -385,7 +391,6 @@ var ElemHide = exports.ElemHide = |
| if (provideFilterKeys) |
| return [selectors, filterKeys]; |
| - else |
| - return selectors; |
| + return selectors; |
| } |
| }; |