| Index: lib/filterClasses.js |
| diff --git a/lib/filterClasses.js b/lib/filterClasses.js |
| index 8ef7869d34c8bc4cefc54f54854d3264ef64ac35..f15225ffaa602c15f2860bc87c6538b38f5b8207 100644 |
| --- a/lib/filterClasses.js |
| +++ b/lib/filterClasses.js |
| @@ -15,6 +15,8 @@ |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| +"use strict"; |
| + |
| /** |
| * @fileOverview Definition of Filter class and its subclasses. |
| */ |
| @@ -40,19 +42,19 @@ Filter.prototype = |
| { |
| /** |
| * String representation of the filter |
| - * @type String |
| + * @type {String} |
|
Sebastian Noack
2017/02/20 13:14:51
This should be "string", not "String". The former
kzar
2017/02/21 06:13:59
Done.
|
| */ |
| text: null, |
| /** |
| * Filter subscriptions the filter belongs to |
| - * @type Subscription[] |
| + * @type {Subscription[]} |
| */ |
| subscriptions: null, |
| /** |
| * Filter type as a string, e.g. "blocking". |
| - * @type String |
| + * @type {String} |
| */ |
| get type() |
| { |
| @@ -63,13 +65,13 @@ Filter.prototype = |
| * Serializes the filter to an array of strings for writing out on the disk. |
| * @param {string[]} buffer buffer to push the serialization results into |
| */ |
| - serialize: function(buffer) |
| + serialize(buffer) |
| { |
| buffer.push("[Filter]"); |
| buffer.push("text=" + this.text); |
| }, |
| - toString: function() |
| + toString() |
| { |
| return this.text; |
| } |
| @@ -77,29 +79,33 @@ Filter.prototype = |
| /** |
| * Cache for known filters, maps string representation to filter objects. |
| - * @type Object |
| + * @type {Object} |
| */ |
| Filter.knownFilters = Object.create(null); |
| +/* eslint-disable max-len */ |
|
Sebastian Noack
2017/02/20 13:14:51
The "max-len" rule has an "ignoreRegExpLiterals" o
kzar
2017/02/21 06:13:59
Done. https://codereview.adblockplus.org/29376671/
|
| + |
| /** |
| * Regular expression that element hiding filters should match |
| - * @type RegExp |
| + * @type {RegExp} |
| */ |
| -Filter.elemhideRegExp = /^([^\/\*\|\@"!]*?)#(\@)?(?:([\w\-]+|\*)((?:\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\))*)|#(.+))$/; |
| +Filter.elemhideRegExp = /^([^/*|@"!]*?)#(@)?(?:([\w-]+|\*)((?:\([\w-]+(?:[$^*]?=[^()"]*)?\))*)|#(.+))$/; |
| /** |
| * Regular expression that RegExp filters specified as RegExps should match |
| - * @type RegExp |
| + * @type {RegExp} |
| */ |
| -Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*)?$/; |
| +Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)?$/; |
| /** |
| * Regular expression that options on a RegExp filter should match |
| - * @type RegExp |
| + * @type {RegExp} |
| */ |
| -Filter.optionsRegExp = /\$(~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*)$/; |
| +Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/; |
| + |
| +/* eslint-enable max-len */ |
| /** |
| - * Creates a filter of correct type from its text representation - does the basic parsing and |
| - * calls the right constructor then. |
| + * Creates a filter of correct type from its text representation - |
| + * does the basic parsing and calls the right constructor then. |
| * |
| * @param {String} text as in Filter() |
| * @return {Filter} |
| @@ -110,9 +116,15 @@ Filter.fromText = function(text) |
| return Filter.knownFilters[text]; |
| let ret; |
| - let match = (text.indexOf("#") >= 0 ? Filter.elemhideRegExp.exec(text) : null); |
| + let match = ( |
|
Sebastian Noack
2017/02/20 13:14:51
Better than wrapping, just use the more concise in
kzar
2017/02/21 06:13:59
Done.
|
| + text.indexOf("#") >= 0 ? Filter.elemhideRegExp.exec(text) : null |
| + ); |
| if (match) |
| - ret = ElemHideBase.fromText(text, match[1], !!match[2], match[3], match[4], match[5]); |
| + { |
| + ret = ElemHideBase.fromText( |
| + text, match[1], !!match[2], match[3], match[4], match[5] |
| + ); |
| + } |
| else if (text[0] == "!") |
| ret = new CommentFilter(text); |
| else |
| @@ -136,9 +148,9 @@ Filter.fromObject = function(obj) |
| if ("disabled" in obj) |
| ret._disabled = (obj.disabled == "true"); |
| if ("hitCount" in obj) |
| - ret._hitCount = parseInt(obj.hitCount) || 0; |
| + ret._hitCount = parseInt(obj.hitCount, 10) || 0; |
| if ("lastHit" in obj) |
| - ret._lastHit = parseInt(obj.lastHit) || 0; |
| + ret._lastHit = parseInt(obj.lastHit, 10) || 0; |
| } |
| return ret; |
| }; |
| @@ -146,8 +158,10 @@ Filter.fromObject = function(obj) |
| /** |
| * Removes unnecessary whitespaces from filter text, will only return null if |
| * the input parameter is null. |
| + * @param {String} text |
| + * @return {String} |
| */ |
| -Filter.normalize = function(/**String*/ text) /**String*/ |
| +Filter.normalize = function(text) |
| { |
| if (!text) |
| return text; |
| @@ -162,12 +176,12 @@ Filter.normalize = function(/**String*/ text) /**String*/ |
| } |
| else if (Filter.elemhideRegExp.test(text)) |
| { |
| - // Special treatment for element hiding filters, right side is allowed to contain spaces |
| - let [, domain, separator, selector] = /^(.*?)(#\@?#?)(.*)$/.exec(text); |
| + // Special treatment for element hiding filters, right side is |
| + // allowed to contain spaces |
| + let [, domain, separator, selector] = /^(.*?)(#@?#?)(.*)$/.exec(text); |
| return domain.replace(/\s/g, "") + separator + selector.trim(); |
| } |
| - else |
| - return text.replace(/\s/g, ""); |
| + return text.replace(/\s/g, ""); |
| }; |
| /** |
| @@ -195,14 +209,15 @@ InvalidFilter.prototype = extend(Filter, { |
| /** |
| * Reason why this filter is invalid |
| - * @type String |
| + * @type {String} |
| */ |
| reason: null, |
| /** |
| * See Filter.serialize() |
| + * @param {string[]} buffer buffer to push the serialization results into |
| */ |
| - serialize: function(buffer) {} |
| + serialize(buffer) {} |
| }); |
| /** |
| @@ -222,14 +237,16 @@ CommentFilter.prototype = extend(Filter, { |
| /** |
| * See Filter.serialize() |
| + * @param {string[]} buffer buffer to push the serialization results into |
| */ |
| - serialize: function(buffer) {} |
| + serialize(buffer) {} |
| }); |
| /** |
| * Abstract base class for filters that can get hits |
| * @param {String} text see Filter() |
| - * @param {String} [domains] Domains that the filter is restricted to separated by domainSeparator e.g. "foo.com|bar.com|~baz.com" |
| + * @param {String} [domains] Domains that the filter is restricted to |
| + * separated by domainSeparator e.g. "foo.com|bar.com|~baz.com" |
| * @constructor |
| * @augments Filter |
| */ |
| @@ -248,7 +265,7 @@ ActiveFilter.prototype = extend(Filter, { |
| /** |
| * Defines whether the filter is disabled |
| - * @type Boolean |
| + * @type {Boolean} |
|
Sebastian Noack
2017/02/20 13:14:51
This should be "boolean", not "Boolean". The forme
kzar
2017/02/21 06:13:58
Done.
|
| */ |
| get disabled() |
| { |
| @@ -267,7 +284,7 @@ ActiveFilter.prototype = extend(Filter, { |
| /** |
| * Number of hits on the filter since the last reset |
| - * @type Number |
| + * @type {Number} |
| */ |
| get hitCount() |
| { |
| @@ -285,8 +302,9 @@ ActiveFilter.prototype = extend(Filter, { |
| }, |
| /** |
| - * Last time the filter had a hit (in milliseconds since the beginning of the epoch) |
| - * @type Number |
| + * Last time the filter had a hit (in milliseconds since the |
| + * beginning of the epoch) |
| + * @type {Number} |
| */ |
| get lastHit() |
| { |
| @@ -305,33 +323,35 @@ ActiveFilter.prototype = extend(Filter, { |
| /** |
| * String that the domains property should be generated from |
| - * @type String |
| + * @type {String} |
| */ |
| domainSource: null, |
| /** |
| - * Separator character used in domainSource property, must be overridden by subclasses |
| - * @type String |
| + * Separator character used in domainSource property, must be |
| + * overridden by subclasses |
| + * @type {String} |
| */ |
| domainSeparator: null, |
| /** |
| * Determines whether the trailing dot in domain names isn't important and |
| * should be ignored, must be overridden by subclasses. |
| - * @type Boolean |
| + * @type {Boolean} |
| */ |
| ignoreTrailingDot: true, |
| /** |
| * Determines whether domainSource is already upper-case, |
| * can be overridden by subclasses. |
| - * @type Boolean |
| + * @type {Boolean} |
| */ |
| domainSourceIsUpperCase: false, |
| /** |
| - * Map containing domains that this filter should match on/not match on or null if the filter should match on all domains |
| - * @type Object |
| + * Map containing domains that this filter should match on/not match |
| + * on or null if the filter should match on all domains |
| + * @type {Object} |
| */ |
| get domains() |
| { |
| @@ -346,7 +366,8 @@ ActiveFilter.prototype = extend(Filter, { |
| if (this.domainSource) |
| { |
| let source = this.domainSource; |
| - if (!this.domainSourceIsUpperCase) { |
| + if (!this.domainSourceIsUpperCase) |
| + { |
| // RegExpFilter already have uppercase domains |
| source = source.toUpperCase(); |
| } |
| @@ -401,7 +422,7 @@ ActiveFilter.prototype = extend(Filter, { |
| /** |
| * Array containing public keys of websites that this filter should apply to |
| - * @type string[] |
| + * @type {string[]} |
| */ |
| sitekeys: null, |
| @@ -411,18 +432,21 @@ ActiveFilter.prototype = extend(Filter, { |
| * @param {String} [sitekey] public key provided by the document |
| * @return {Boolean} true in case of the filter being active |
| */ |
| - isActiveOnDomain: function(docDomain, sitekey) |
| + isActiveOnDomain(docDomain, sitekey) |
| { |
| - // Sitekeys are case-sensitive so we shouldn't convert them to upper-case to avoid false |
| - // positives here. Instead we need to change the way filter options are parsed. |
| - if (this.sitekeys && (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) |
| + // Sitekeys are case-sensitive so we shouldn't convert them to |
| + // upper-case to avoid false positives here. Instead we need to |
| + // change the way filter options are parsed. |
| + if (this.sitekeys && |
| + (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) |
| return false; |
| // If no domains are set the rule matches everywhere |
| if (!this.domains) |
| return true; |
| - // If the document has no host name, match only if the filter isn't restricted to specific domains |
| + // If the document has no host name, match only if the filter |
| + // isn't restricted to specific domains |
| if (!docDomain) |
| return this.domains[""]; |
| @@ -430,6 +454,7 @@ ActiveFilter.prototype = extend(Filter, { |
| docDomain = docDomain.replace(/\.+$/, ""); |
| docDomain = docDomain.toUpperCase(); |
| + /* eslint-disable no-constant-condition */ |
| while (true) |
| { |
| if (docDomain in this.domains) |
| @@ -440,13 +465,16 @@ ActiveFilter.prototype = extend(Filter, { |
| break; |
| docDomain = docDomain.substr(nextDot + 1); |
| } |
| + /* eslint-enable no-constant-condition */ |
| return this.domains[""]; |
| }, |
| /** |
| * Checks whether this filter is active only on a domain and its subdomains. |
| + * @param {String} docDomain |
| + * @return {Boolean} |
| */ |
| - isActiveOnlyOnDomain: function(/**String*/ docDomain) /**Boolean*/ |
| + isActiveOnlyOnDomain(docDomain) |
| { |
| if (!docDomain || !this.domains || this.domains[""]) |
| return false; |
| @@ -456,16 +484,22 @@ ActiveFilter.prototype = extend(Filter, { |
| docDomain = docDomain.toUpperCase(); |
| for (let domain in this.domains) |
| - if (this.domains[domain] && domain != docDomain && (domain.length <= docDomain.length || domain.indexOf("." + docDomain) != domain.length - docDomain.length - 1)) |
| + { |
| + if (this.domains[domain] && domain != docDomain && |
| + (domain.length <= docDomain.length || |
| + domain.indexOf("." + docDomain) != |
| + domain.length - docDomain.length - 1)) |
| return false; |
| + } |
| return true; |
| }, |
| /** |
| * Checks whether this filter is generic or specific |
| + * @return {Boolean} |
| */ |
| - isGeneric: function() /**Boolean*/ |
| + isGeneric() |
| { |
| return !(this.sitekeys && this.sitekeys.length) && |
| (!this.domains || this.domains[""]); |
| @@ -473,8 +507,9 @@ ActiveFilter.prototype = extend(Filter, { |
| /** |
| * See Filter.serialize() |
| + * @param {string[]} buffer buffer to push the serialization results into |
| */ |
| - serialize: function(buffer) |
| + serialize(buffer) |
| { |
| if (this._disabled || this._hitCount || this._lastHit) |
| { |
| @@ -492,16 +527,23 @@ ActiveFilter.prototype = extend(Filter, { |
| /** |
| * Abstract base class for RegExp-based filters |
| * @param {String} text see Filter() |
| - * @param {String} regexpSource filter part that the regular expression should be build from |
| - * @param {Number} [contentType] Content types the filter applies to, combination of values from RegExpFilter.typeMap |
| - * @param {Boolean} [matchCase] Defines whether the filter should distinguish between lower and upper case letters |
| - * @param {String} [domains] Domains that the filter is restricted to, e.g. "foo.com|bar.com|~baz.com" |
| - * @param {Boolean} [thirdParty] Defines whether the filter should apply to third-party or first-party content only |
| - * @param {String} [sitekeys] Public keys of websites that this filter should apply to |
| + * @param {String} regexpSource filter part that the regular expression should |
| + * be build from |
| + * @param {Number} [contentType] Content types the filter applies to, |
| + * combination of values from RegExpFilter.typeMap |
| + * @param {Boolean} [matchCase] Defines whether the filter should distinguish |
| + * between lower and upper case letters |
| + * @param {String} [domains] Domains that the filter is restricted to, |
| + * e.g. "foo.com|bar.com|~baz.com" |
| + * @param {Boolean} [thirdParty] Defines whether the filter should apply to |
| + * third-party or first-party content only |
| + * @param {String} [sitekeys] Public keys of websites that this filter should |
| + * apply to |
| * @constructor |
| * @augments ActiveFilter |
| */ |
| -function RegExpFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys) |
| +function RegExpFilter(text, regexpSource, contentType, matchCase, domains, |
| + thirdParty, sitekeys) |
| { |
| ActiveFilter.call(this, text, domains, sitekeys); |
| @@ -514,10 +556,14 @@ function RegExpFilter(text, regexpSource, contentType, matchCase, domains, third |
| if (sitekeys != null) |
| this.sitekeySource = sitekeys; |
| - if (regexpSource.length >= 2 && regexpSource[0] == "/" && regexpSource[regexpSource.length - 1] == "/") |
| + if (regexpSource.length >= 2 && |
| + regexpSource[0] == "/" && |
| + regexpSource[regexpSource.length - 1] == "/") |
| { |
| - // The filter is a regular expression - convert it immediately to catch syntax errors |
| - let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), this.matchCase ? "" : "i"); |
| + // The filter is a regular expression - convert it immediately to |
| + // catch syntax errors |
| + let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), |
| + this.matchCase ? "" : "i"); |
| Object.defineProperty(this, "regexp", {value: regexp}); |
| } |
| else |
| @@ -535,8 +581,9 @@ RegExpFilter.prototype = extend(ActiveFilter, { |
| domainSourceIsUpperCase: true, |
| /** |
| - * Number of filters contained, will always be 1 (required to optimize Matcher). |
| - * @type Integer |
| + * Number of filters contained, will always be 1 (required to |
| + * optimize Matcher). |
| + * @type {Integer} |
| */ |
| length: 1, |
| @@ -546,13 +593,14 @@ RegExpFilter.prototype = extend(ActiveFilter, { |
| domainSeparator: "|", |
| /** |
| - * Expression from which a regular expression should be generated - for delayed creation of the regexp property |
| - * @type String |
| + * Expression from which a regular expression should be generated - |
| + * for delayed creation of the regexp property |
| + * @type {String} |
| */ |
| regexpSource: null, |
| /** |
| * Regular expression to be used when testing against this filter |
| - * @type RegExp |
| + * @type {RegExp} |
| */ |
| get regexp() |
| { |
| @@ -568,30 +616,33 @@ RegExpFilter.prototype = extend(ActiveFilter, { |
| return regexp; |
| }, |
| /** |
| - * Content types the filter applies to, combination of values from RegExpFilter.typeMap |
| - * @type Number |
| + * Content types the filter applies to, combination of values from |
| + * RegExpFilter.typeMap |
| + * @type {Number} |
| */ |
| contentType: 0x7FFFFFFF, |
| /** |
| - * Defines whether the filter should distinguish between lower and upper case letters |
| - * @type Boolean |
| + * Defines whether the filter should distinguish between lower and |
| + * upper case letters |
| + * @type {Boolean} |
| */ |
| matchCase: false, |
| /** |
| - * Defines whether the filter should apply to third-party or first-party content only. Can be null (apply to all content). |
| - * @type Boolean |
| + * Defines whether the filter should apply to third-party or |
| + * first-party content only. Can be null (apply to all content). |
| + * @type {Boolean} |
| */ |
| thirdParty: null, |
| /** |
| * String that the sitekey property should be generated from |
| - * @type String |
| + * @type {String} |
| */ |
| sitekeySource: null, |
| /** |
| * Array containing public keys of websites that this filter should apply to |
| - * @type string[] |
| + * @type {string[]} |
| */ |
| get sitekeys() |
| { |
| @@ -609,7 +660,9 @@ RegExpFilter.prototype = extend(ActiveFilter, { |
| this.sitekeySource = null; |
| } |
| - Object.defineProperty(this, "sitekeys", {value: sitekeys, enumerable: true}); |
| + Object.defineProperty( |
| + this, "sitekeys", {value: sitekeys, enumerable: true} |
| + ); |
| return this.sitekeys; |
| }, |
| @@ -618,32 +671,30 @@ RegExpFilter.prototype = extend(ActiveFilter, { |
| * @param {String} location URL to be tested |
| * @param {number} typeMask bitmask of content / request types to match |
| * @param {String} docDomain domain name of the document that loads the URL |
| - * @param {Boolean} thirdParty should be true if the URL is a third-party request |
| + * @param {Boolean} thirdParty should be true if the URL is a third-party |
| + * request |
| * @param {String} sitekey public key provided by the document |
| * @return {Boolean} true in case of a match |
| */ |
| - matches: function(location, typeMask, docDomain, thirdParty, sitekey) |
| + matches(location, typeMask, docDomain, thirdParty, sitekey) |
| { |
| if (this.contentType & typeMask && |
| (this.thirdParty == null || this.thirdParty == thirdParty) && |
| this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) |
| - { |
| return true; |
| - } |
| - |
| return false; |
| } |
| }); |
| // Required to optimize Matcher, see also RegExpFilter.prototype.length |
| -Object.defineProperty(RegExpFilter.prototype, "0", |
| -{ |
| - get: function() { return this; } |
| +Object.defineProperty(RegExpFilter.prototype, "0", { |
| + get() { return this; } |
| }); |
| /** |
| * Creates a RegExp filter from its text representation |
| * @param {String} text same as in Filter() |
| + * @return {RegExpFilter} |
| */ |
| RegExpFilter.fromText = function(text) |
| { |
| @@ -686,7 +737,7 @@ RegExpFilter.fromText = function(text) |
| else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) |
| { |
| if (contentType == null) |
| - contentType = RegExpFilter.prototype.contentType; |
| + ({contentType} = RegExpFilter.prototype); |
| contentType &= ~RegExpFilter.typeMap[option.substr(1)]; |
| } |
| else if (option == "MATCH_CASE") |
| @@ -713,9 +764,12 @@ RegExpFilter.fromText = function(text) |
| try |
| { |
| if (blocking) |
| - return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse); |
| - else |
| - return new WhitelistFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys); |
| + { |
| + return new BlockingFilter(origText, text, contentType, matchCase, domains, |
| + thirdParty, sitekeys, collapse); |
| + } |
| + return new WhitelistFilter(origText, text, contentType, matchCase, domains, |
| + thirdParty, sitekeys); |
| } |
| catch (e) |
| { |
| @@ -768,13 +822,16 @@ RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | |
| * @param {String} domains see RegExpFilter() |
| * @param {Boolean} thirdParty see RegExpFilter() |
| * @param {String} sitekeys see RegExpFilter() |
| - * @param {Boolean} collapse defines whether the filter should collapse blocked content, can be null |
| + * @param {Boolean} collapse defines whether the filter should collapse blocked |
| + * content, can be null |
| * @constructor |
| * @augments RegExpFilter |
| */ |
| -function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys, collapse) |
| +function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
| + thirdParty, sitekeys, collapse) |
| { |
| - RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys); |
| + RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
| + thirdParty, sitekeys); |
| this.collapse = collapse; |
| } |
| @@ -784,8 +841,9 @@ BlockingFilter.prototype = extend(RegExpFilter, { |
| type: "blocking", |
| /** |
| - * Defines whether the filter should collapse blocked content. Can be null (use the global preference). |
| - * @type Boolean |
| + * Defines whether the filter should collapse blocked content. |
| + * Can be null (use the global preference). |
| + * @type {Boolean} |
| */ |
| collapse: null |
| }); |
| @@ -802,9 +860,11 @@ BlockingFilter.prototype = extend(RegExpFilter, { |
| * @constructor |
| * @augments RegExpFilter |
| */ |
| -function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys) |
| +function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, |
| + thirdParty, sitekeys) |
| { |
| - RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys); |
| + RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
| + thirdParty, sitekeys); |
| } |
| exports.WhitelistFilter = WhitelistFilter; |
| @@ -815,8 +875,10 @@ WhitelistFilter.prototype = extend(RegExpFilter, { |
| /** |
| * Base class for element hiding filters |
| * @param {String} text see Filter() |
| - * @param {String} [domains] Host names or domains the filter should be restricted to |
| - * @param {String} selector CSS selector for the HTML elements that should be hidden |
| + * @param {String} [domains] Host names or domains the filter should be |
| + * restricted to |
| + * @param {String} selector CSS selector for the HTML elements that should be |
| + * hidden |
| * @constructor |
| * @augments ActiveFilter |
| */ |
| @@ -825,7 +887,10 @@ function ElemHideBase(text, domains, selector) |
| ActiveFilter.call(this, text, domains || null); |
| if (domains) |
| - this.selectorDomain = domains.replace(/,~[^,]+/g, "").replace(/^~[^,]+,?/, "").toLowerCase(); |
| + { |
| + this.selectorDomain = domains.replace(/,~[^,]+/g, ""). |
| + replace(/^~[^,]+,?/, "").toLowerCase(); |
| + } |
| // Braces are being escaped to prevent CSS rule injection. |
| this.selector = selector.replace("{", "\\x7B ").replace("}", "\\x7D "); |
| @@ -844,13 +909,14 @@ ElemHideBase.prototype = extend(ActiveFilter, { |
| ignoreTrailingDot: false, |
| /** |
| - * Host name or domain the filter should be restricted to (can be null for no restriction) |
| - * @type String |
| + * Host name or domain the filter should be restricted to (can be null for |
| + * no restriction) |
| + * @type {String} |
| */ |
| selectorDomain: null, |
| /** |
| * CSS selector for the HTML elements that should be hidden |
| - * @type String |
| + * @type {String} |
| */ |
| selector: null |
| }); |
| @@ -859,14 +925,17 @@ ElemHideBase.prototype = extend(ActiveFilter, { |
| * Creates an element hiding filter from a pre-parsed text representation |
| * |
| * @param {String} text same as in Filter() |
| - * @param {String} domain domain part of the text representation (can be empty) |
| + * @param {String} domain domain part of the text representation |
| + * (can be empty) |
| * @param {Boolean} isException exception rule indicator |
| * @param {String} tagName tag name part (can be empty) |
| * @param {String} attrRules attribute matching rules (can be empty) |
| * @param {String} selector raw CSS selector (can be empty) |
| - * @return {ElemHideFilter|ElemHideException|ElemHideEmulationFilter|InvalidFilter} |
| + * @return {ElemHideFilter|ElemHideException| |
| + * ElemHideEmulationFilter|InvalidFilter} |
| */ |
| -ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, selector) |
| +ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, |
| + selector) |
| { |
| if (!selector) |
| { |
| @@ -877,7 +946,7 @@ ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, |
| let additional = ""; |
| if (attrRules) |
| { |
| - attrRules = attrRules.match(/\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\)/g); |
| + attrRules = attrRules.match(/\([\w-]+(?:[$^*]?=[^()"]*)?\)/g); |
| for (let rule of attrRules) |
| { |
| rule = rule.substr(1, rule.length - 2); |
| @@ -898,7 +967,10 @@ ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, |
| } |
| if (id) |
| - selector = tagName + "." + id + additional + "," + tagName + "#" + id + additional; |
| + { |
| + selector = tagName + "." + id + additional + "," + tagName + |
|
Sebastian Noack
2017/02/20 13:14:51
This can be written in one line (with <80 characte
kzar
2017/02/21 06:13:59
Done.
|
| + "#" + id + additional; |
| + } |
| else if (tagName || additional) |
| selector = tagName + additional; |
| else |