Index: lib/filterClasses.js |
diff --git a/lib/filterClasses.js b/lib/filterClasses.js |
index 8ef7869d34c8bc4cefc54f54854d3264ef64ac35..8cf4af96b65b5a0430de91f0c6060bbe6f7ee962 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. |
*/ |
@@ -26,7 +28,7 @@ let {filterToRegExp} = require("common"); |
/** |
* Abstract base class for filters |
* |
- * @param {String} text string representation of the filter |
+ * @param {string} text string representation of the filter |
* @constructor |
*/ |
function Filter(text) |
@@ -40,19 +42,19 @@ Filter.prototype = |
{ |
/** |
* String representation of the filter |
- * @type String |
+ * @type {string} |
*/ |
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,31 +79,31 @@ Filter.prototype = |
/** |
* Cache for known filters, maps string representation to filter objects. |
- * @type Object |
+ * @type {Object} |
*/ |
Filter.knownFilters = Object.create(null); |
/** |
* 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]+)?)*)$/; |
/** |
- * 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() |
+ * @param {string} text as in Filter() |
* @return {Filter} |
*/ |
Filter.fromText = function(text) |
@@ -110,9 +112,13 @@ Filter.fromText = function(text) |
return Filter.knownFilters[text]; |
let ret; |
- let match = (text.indexOf("#") >= 0 ? Filter.elemhideRegExp.exec(text) : null); |
+ let match = (text.includes("#") ? 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 +142,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 +152,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 +170,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, ""); |
}; |
/** |
@@ -177,8 +185,8 @@ Filter.toRegExp = filterToRegExp; |
/** |
* Class for invalid filters |
- * @param {String} text see Filter() |
- * @param {String} reason Reason why this filter is invalid |
+ * @param {string} text see Filter() |
+ * @param {string} reason Reason why this filter is invalid |
* @constructor |
* @augments Filter |
*/ |
@@ -195,19 +203,20 @@ 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) {} |
}); |
/** |
* Class for comments |
- * @param {String} text see Filter() |
+ * @param {string} text see Filter() |
* @constructor |
* @augments Filter |
*/ |
@@ -222,14 +231,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} text see Filter() |
+ * @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 +259,7 @@ ActiveFilter.prototype = extend(Filter, { |
/** |
* Defines whether the filter is disabled |
- * @type Boolean |
+ * @type {boolean} |
*/ |
get disabled() |
{ |
@@ -267,7 +278,7 @@ ActiveFilter.prototype = extend(Filter, { |
/** |
* Number of hits on the filter since the last reset |
- * @type Number |
+ * @type {Number} |
*/ |
get hitCount() |
{ |
@@ -285,8 +296,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 +317,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 +360,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,28 +416,31 @@ ActiveFilter.prototype = extend(Filter, { |
/** |
* Array containing public keys of websites that this filter should apply to |
- * @type string[] |
+ * @type {string[]} |
*/ |
sitekeys: null, |
/** |
* Checks whether this filter is active on a domain. |
- * @param {String} docDomain domain name of the document that loads the URL |
- * @param {String} [sitekey] public key provided by the document |
- * @return {Boolean} true in case of the filter being active |
+ * @param {string} docDomain domain name of the document that loads the URL |
+ * @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[""]; |
@@ -445,8 +463,10 @@ ActiveFilter.prototype = extend(Filter, { |
/** |
* 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 +476,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)) |
Sebastian Noack
2017/02/21 09:19:31
Perhaps this rather complex condition is either to
kzar
2017/02/21 10:37:01
Looks much clearer to me, Done.
|
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 +499,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) |
{ |
@@ -491,17 +518,24 @@ 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} 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 |
* @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 +548,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 +573,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 {number} |
*/ |
length: 1, |
@@ -546,13 +585,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 +608,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,41 +652,41 @@ 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; |
}, |
/** |
* Tests whether the URL matches this filter |
- * @param {String} location URL to be tested |
+ * @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 {String} sitekey public key provided by the document |
- * @return {Boolean} true in case of a 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 {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() |
+ * @param {string} text same as in Filter() |
+ * @return {RegExpFilter} |
*/ |
RegExpFilter.fromText = function(text) |
{ |
@@ -686,7 +729,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 +756,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) |
{ |
@@ -761,20 +807,23 @@ RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | |
/** |
* Class for blocking filters |
- * @param {String} text see Filter() |
- * @param {String} regexpSource see RegExpFilter() |
+ * @param {string} text see Filter() |
+ * @param {string} regexpSource see RegExpFilter() |
* @param {Number} contentType see RegExpFilter() |
- * @param {Boolean} matchCase see RegExpFilter() |
- * @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} matchCase see RegExpFilter() |
+ * @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 |
* @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,27 +833,30 @@ 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 |
}); |
/** |
* Class for whitelist filters |
- * @param {String} text see Filter() |
- * @param {String} regexpSource see RegExpFilter() |
+ * @param {string} text see Filter() |
+ * @param {string} regexpSource see RegExpFilter() |
* @param {Number} contentType see RegExpFilter() |
- * @param {Boolean} matchCase see RegExpFilter() |
- * @param {String} domains see RegExpFilter() |
- * @param {Boolean} thirdParty see RegExpFilter() |
- * @param {String} sitekeys see RegExpFilter() |
+ * @param {boolean} matchCase see RegExpFilter() |
+ * @param {string} domains see RegExpFilter() |
+ * @param {boolean} thirdParty see RegExpFilter() |
+ * @param {string} sitekeys see 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; |
@@ -814,9 +866,11 @@ 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} 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 |
* @constructor |
* @augments ActiveFilter |
*/ |
@@ -825,7 +879,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(); |
Sebastian Noack
2017/02/21 09:19:30
I think it's more readable when indented like this
kzar
2017/02/21 10:37:01
Done.
|
+ } |
// Braces are being escaped to prevent CSS rule injection. |
this.selector = selector.replace("{", "\\x7B ").replace("}", "\\x7D "); |
@@ -844,13 +901,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 |
}); |
@@ -858,15 +916,18 @@ 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 {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} |
+ * @param {string} text same as in Filter() |
+ * @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} |
*/ |
-ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, selector) |
+ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, |
+ selector) |
{ |
if (!selector) |
{ |
@@ -877,7 +938,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 +959,7 @@ ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, |
} |
if (id) |
- selector = tagName + "." + id + additional + "," + tagName + "#" + id + additional; |
+ selector = `${tagName}.${id}${additional},${tagName}#${id}${additional}`; |
else if (tagName || additional) |
selector = tagName + additional; |
else |
@@ -929,9 +990,9 @@ ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules, |
/** |
* Class for element hiding filters |
- * @param {String} text see Filter() |
- * @param {String} domains see ElemHideBase() |
- * @param {String} selector see ElemHideBase() |
+ * @param {string} text see Filter() |
+ * @param {string} domains see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
* @constructor |
* @augments ElemHideBase |
*/ |
@@ -947,9 +1008,9 @@ ElemHideFilter.prototype = extend(ElemHideBase, { |
/** |
* Class for element hiding exceptions |
- * @param {String} text see Filter() |
- * @param {String} domains see ElemHideBase() |
- * @param {String} selector see ElemHideBase() |
+ * @param {string} text see Filter() |
+ * @param {string} domains see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
* @constructor |
* @augments ElemHideBase |
*/ |
@@ -965,9 +1026,9 @@ ElemHideException.prototype = extend(ElemHideBase, { |
/** |
* Class for element hiding emulation filters |
- * @param {String} text see Filter() |
- * @param {String} domains see ElemHideBase() |
- * @param {String} selector see ElemHideBase() |
+ * @param {string} text see Filter() |
+ * @param {string} domains see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
* @constructor |
* @augments ElemHideBase |
*/ |