| Index: lib/elemHide.js |
| =================================================================== |
| --- a/lib/elemHide.js |
| +++ b/lib/elemHide.js |
| @@ -58,16 +58,27 @@ |
| /** |
| * Lookup table, lists of element hiding exceptions by selector |
| * @type {Map.<string,Filter>} |
| */ |
| let exceptions = new Map(); |
| /** |
| + * Returns a list of selectors that apply on each website unconditionally. |
| + * @returns {string[]} |
| + */ |
| +function getUnconditionalSelectors() |
| +{ |
| + if (!unconditionalSelectors) |
| + unconditionalSelectors = [...filterBySelector.keys()]; |
| + return unconditionalSelectors; |
| +} |
| + |
| +/** |
| * Container for element hiding filters |
| * @class |
| */ |
| let ElemHide = exports.ElemHide = { |
| /** |
| * Removes all known filters |
| */ |
| clear() |
| @@ -199,27 +210,16 @@ |
| if (list[i].isActiveOnDomain(docDomain)) |
| return list[i]; |
| } |
| return null; |
| }, |
| /** |
| - * Returns a list of selectors that apply on each website unconditionally. |
| - * @returns {string[]} |
| - */ |
| - getUnconditionalSelectors() |
| - { |
| - if (!unconditionalSelectors) |
| - unconditionalSelectors = [...filterBySelector.keys()]; |
| - return unconditionalSelectors.slice(); |
| - }, |
| - |
| - /** |
| * Constant used by getSelectorsForDomain to return all selectors applying to |
| * a particular hostname. |
| */ |
| ALL_MATCHING: 0, |
| /** |
| * Constant used by getSelectorsForDomain to exclude selectors which apply to |
| * all websites without exception. |
| @@ -237,26 +237,22 @@ |
| * on a particular host name. |
| * @param {string} domain |
| * @param {number} [criteria] |
| * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or |
| * ElemHide.SPECIFIC_ONLY. |
| * @returns {string[]} |
| * List of selectors. |
| */ |
| - getSelectorsForDomain(domain, criteria) |
| + getSelectorsForDomain(domain, criteria = ElemHide.ALL_MATCHING) |
|
Manish Jethani
2018/05/08 17:34:25
This is the modern way of specifying default value
|
| { |
| let selectors = []; |
| - if (typeof criteria == "undefined") |
| - criteria = ElemHide.ALL_MATCHING; |
| - if (criteria < ElemHide.NO_UNCONDITIONAL) |
| - selectors = this.getUnconditionalSelectors(); |
| + let specificOnly = criteria >= ElemHide.SPECIFIC_ONLY; |
| - let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); |
| let excluded = new Set(); |
| let currentDomain = domain ? domain.toUpperCase() : ""; |
| // This code is a performance hot-spot, which is why we've made certain |
| // micro-optimisations. Please be careful before making changes. |
| while (true) |
| { |
| if (specificOnly && currentDomain == "") |
| @@ -281,11 +277,14 @@ |
| if (currentDomain == "") |
| break; |
| let nextDot = currentDomain.indexOf("."); |
| currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
| } |
| + if (criteria < ElemHide.NO_UNCONDITIONAL) |
| + selectors = getUnconditionalSelectors().concat(selectors); |
| + |
| return selectors; |
| } |
| }; |