Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -17,70 +17,67 @@ |
"use strict"; |
/** |
* @fileOverview Definition of Filter class and its subclasses. |
*/ |
const {FilterNotifier} = require("./filterNotifier"); |
-const {extend} = require("./coreUtils"); |
const {filterToRegExp} = require("./common"); |
/** |
* Abstract base class for filters |
- * |
- * @param {string} text string representation of the filter |
- * @constructor |
*/ |
-function Filter(text) |
-{ |
- this.text = text; |
- this.subscriptions = []; |
-} |
-exports.Filter = Filter; |
- |
-Filter.prototype = |
+class Filter |
{ |
/** |
- * String representation of the filter |
- * @type {string} |
+ * @param {string} text string representation of the filter |
*/ |
- text: null, |
+ constructor(text) |
+ { |
+ /** |
Manish Jethani
2018/06/09 13:03:32
For instance properties that are always assigned i
|
+ * String representation of the filter |
+ * @type {string} |
+ */ |
+ this.text = text; |
- /** |
- * Filter subscriptions the filter belongs to |
- * @type {Subscription[]} |
- */ |
- subscriptions: null, |
+ /** |
+ * Filter subscriptions the filter belongs to |
+ * @type {Subscription[]} |
+ */ |
+ this.subscriptions = []; |
+ } |
/** |
* Filter type as a string, e.g. "blocking". |
* @type {string} |
*/ |
get type() |
{ |
throw new Error("Please define filter type in the subclass"); |
- }, |
+ } |
/** |
* 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(buffer) |
{ |
buffer.push("[Filter]"); |
buffer.push("text=" + this.text); |
- }, |
+ } |
toString() |
{ |
return this.text; |
} |
-}; |
+} |
+ |
+exports.Filter = Filter; |
/** |
* Cache for known filters, maps string representation to filter objects. |
* @type {Map.<string,Filter>} |
*/ |
Filter.knownFilters = new Map(); |
/** |
@@ -235,168 +232,152 @@ |
/** |
* @see filterToRegExp |
*/ |
Filter.toRegExp = filterToRegExp; |
/** |
* Class for invalid filters |
- * @param {string} text see Filter() |
- * @param {string} reason Reason why this filter is invalid |
- * @constructor |
- * @augments Filter |
*/ |
-function InvalidFilter(text, reason) |
+class InvalidFilter extends Filter |
{ |
- Filter.call(this, text); |
+ /** |
+ * @param {string} text see Filter() |
+ * @param {string} reason Reason why this filter is invalid |
+ */ |
+ constructor(text, reason) |
+ { |
+ super(text); |
- this.reason = reason; |
-} |
-exports.InvalidFilter = InvalidFilter; |
+ /** |
+ * Reason why this filter is invalid |
+ * @type {string} |
+ */ |
+ this.reason = reason; |
+ } |
-InvalidFilter.prototype = extend(Filter, { |
- type: "invalid", |
- |
- /** |
- * Reason why this filter is invalid |
- * @type {string} |
- */ |
- reason: null, |
+ get type() |
Manish Jethani
2018/06/09 13:03:32
This needs to be a getter now.
|
+ { |
+ return "invalid"; |
+ } |
/** |
* See Filter.serialize() |
* @inheritdoc |
*/ |
serialize(buffer) {} |
-}); |
+} |
+ |
+exports.InvalidFilter = InvalidFilter; |
/** |
* Class for comments |
- * @param {string} text see Filter() |
- * @constructor |
- * @augments Filter |
*/ |
-function CommentFilter(text) |
+class CommentFilter extends Filter |
{ |
- Filter.call(this, text); |
-} |
-exports.CommentFilter = CommentFilter; |
+ /** |
+ * @param {string} text see Filter() |
+ */ |
+ constructor(text) |
+ { |
+ super(text); |
+ } |
-CommentFilter.prototype = extend(Filter, { |
- type: "comment", |
+ get type() |
+ { |
+ return "comment"; |
+ } |
/** |
* See Filter.serialize() |
* @inheritdoc |
*/ |
serialize(buffer) {} |
-}); |
+} |
+ |
+exports.CommentFilter = CommentFilter; |
/** |
* 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" |
- * @constructor |
- * @augments Filter |
*/ |
-function ActiveFilter(text, domains) |
+class ActiveFilter extends Filter |
{ |
- Filter.call(this, text); |
+ /** |
+ * @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(text, domains) |
+ { |
+ super(text); |
- if (domains) |
- this.domainSource = domains; |
-} |
-exports.ActiveFilter = ActiveFilter; |
- |
-ActiveFilter.prototype = extend(Filter, { |
- _disabled: false, |
- _hitCount: 0, |
- _lastHit: 0, |
+ if (domains) |
+ this.domainSource = domains; |
+ } |
/** |
* Defines whether the filter is disabled |
* @type {boolean} |
*/ |
get disabled() |
{ |
return this._disabled; |
- }, |
+ } |
set disabled(value) |
{ |
if (value != this._disabled) |
{ |
let oldValue = this._disabled; |
this._disabled = value; |
FilterNotifier.triggerListeners("filter.disabled", this, value, oldValue); |
} |
return this._disabled; |
- }, |
+ } |
/** |
* Number of hits on the filter since the last reset |
* @type {number} |
*/ |
get hitCount() |
{ |
return this._hitCount; |
- }, |
+ } |
set hitCount(value) |
{ |
if (value != this._hitCount) |
{ |
let oldValue = this._hitCount; |
this._hitCount = value; |
FilterNotifier.triggerListeners("filter.hitCount", this, value, oldValue); |
} |
return this._hitCount; |
- }, |
+ } |
/** |
* Last time the filter had a hit (in milliseconds since the beginning of the |
* epoch) |
* @type {number} |
*/ |
get lastHit() |
{ |
return this._lastHit; |
- }, |
+ } |
set lastHit(value) |
{ |
if (value != this._lastHit) |
{ |
let oldValue = this._lastHit; |
this._lastHit = value; |
FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue); |
} |
return this._lastHit; |
- }, |
- |
- /** |
- * String that the domains property should be generated from |
- * @type {?string} |
- */ |
- domainSource: null, |
- |
- /** |
- * Separator character used in domainSource property, must be |
- * overridden by subclasses |
- * @type {string} |
- */ |
- domainSeparator: null, |
- |
- /** |
- * Determines whether domainSource is already upper-case, |
- * can be overridden by subclasses. |
- * @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 {?Map.<string,boolean>} |
*/ |
get domains() |
{ |
@@ -446,23 +427,17 @@ |
domains.set("", !hasIncludes); |
} |
this.domainSource = null; |
} |
Object.defineProperty(this, "domains", {value: domains, enumerable: true}); |
return this.domains; |
- }, |
- |
- /** |
- * Array containing public keys of websites that this filter should apply to |
- * @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 |
*/ |
isActiveOnDomain(docDomain, sitekey) |
@@ -494,17 +469,17 @@ |
return isDomainIncluded; |
let nextDot = docDomain.indexOf("."); |
if (nextDot < 0) |
break; |
docDomain = docDomain.substr(nextDot + 1); |
} |
return this.domains.get(""); |
- }, |
+ } |
/** |
* Checks whether this filter is active only on a domain and its subdomains. |
* @param {string} docDomain |
* @return {boolean} |
*/ |
isActiveOnlyOnDomain(docDomain) |
{ |
@@ -521,27 +496,27 @@ |
return false; |
if (!domain.endsWith("." + docDomain)) |
return false; |
} |
} |
return true; |
- }, |
+ } |
/** |
* Checks whether this filter is generic or specific |
* @return {boolean} |
*/ |
isGeneric() |
{ |
return !(this.sitekeys && this.sitekeys.length) && |
(!this.domains || this.domains.get("")); |
- }, |
+ } |
/** |
* See Filter.serialize() |
* @inheritdoc |
*/ |
serialize(buffer) |
{ |
if (this._disabled || this._hitCount || this._lastHit) |
@@ -550,150 +525,135 @@ |
if (this._disabled) |
buffer.push("disabled=true"); |
if (this._hitCount) |
buffer.push("hitCount=" + this._hitCount); |
if (this._lastHit) |
buffer.push("lastHit=" + this._lastHit); |
} |
} |
+} |
+ |
+exports.ActiveFilter = ActiveFilter; |
+ |
+Object.assign(ActiveFilter.prototype, { |
+ _disabled: false, |
+ _hitCount: 0, |
+ _lastHit: 0 |
}); |
/** |
+ * String that the domains property should be generated from |
+ * @type {?string} |
+ */ |
+ActiveFilter.prototype.domainSource = null; |
Manish Jethani
2018/06/09 13:03:32
Where the instance property is not always assigned
|
+ |
+/** |
+ * Separator character used in domainSource property, must be |
+ * overridden by subclasses |
+ * @type {string} |
+ */ |
+ActiveFilter.prototype.domainSeparator = null; |
+ |
+/** |
+ * Determines whether domainSource is already upper-case, |
+ * can be overridden by subclasses. |
+ * @type {boolean} |
+ */ |
+ActiveFilter.prototype.domainSourceIsUpperCase = false; |
+ |
+/** |
+ * Array containing public keys of websites that this filter should apply to |
+ * @type {?string[]} |
+ */ |
+ActiveFilter.prototype.sitekeys = null; |
+ |
+/** |
* 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 |
- * @constructor |
- * @augments ActiveFilter |
*/ |
-function RegExpFilter(text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys) |
+class RegExpFilter extends ActiveFilter |
{ |
- ActiveFilter.call(this, text, domains, sitekeys); |
- |
- if (contentType != null) |
- this.contentType = contentType; |
- if (matchCase) |
- this.matchCase = matchCase; |
- if (thirdParty != null) |
- this.thirdParty = thirdParty; |
- if (sitekeys != null) |
- this.sitekeySource = sitekeys; |
- |
- if (regexpSource.length >= 2 && |
- regexpSource[0] == "/" && |
- regexpSource[regexpSource.length - 1] == "/") |
+ /** |
+ * @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(text, regexpSource, contentType, matchCase, domains, thirdParty, |
+ sitekeys) |
{ |
- // 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 |
- { |
- // No need to convert this filter to regular expression yet, do it on demand |
- this.regexpSource = regexpSource; |
- } |
-} |
-exports.RegExpFilter = RegExpFilter; |
+ super(text, domains, sitekeys); |
+ |
+ if (contentType != null) |
+ this.contentType = contentType; |
+ if (matchCase) |
+ this.matchCase = matchCase; |
+ if (thirdParty != null) |
+ this.thirdParty = thirdParty; |
+ if (sitekeys != null) |
+ this.sitekeySource = sitekeys; |
-RegExpFilter.prototype = extend(ActiveFilter, { |
- /** |
- * @see ActiveFilter.domainSourceIsUpperCase |
- */ |
- domainSourceIsUpperCase: true, |
+ 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"); |
+ Object.defineProperty(this, "regexp", {value: regexp}); |
+ } |
+ else |
+ { |
+ // No need to convert this filter to regular expression yet, do it on |
+ // demand |
+ this.regexpSource = regexpSource; |
+ } |
+ } |
/** |
- * Number of filters contained, will always be 1 (required to |
- * optimize Matcher). |
- * @type {number} |
- */ |
- length: 1, |
- |
- /** |
- * @see ActiveFilter.domainSeparator |
- */ |
- domainSeparator: "|", |
- |
- /** |
- * 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} |
*/ |
get regexp() |
{ |
let source = Filter.toRegExp(this.regexpSource); |
let regexp = new RegExp(source, this.matchCase ? "" : "i"); |
Object.defineProperty(this, "regexp", {value: regexp}); |
this.regexpSource = null; |
return regexp; |
- }, |
- /** |
- * 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} |
- */ |
- 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} |
- */ |
- thirdParty: null, |
+ } |
- /** |
- * String that the sitekey property should be generated from |
- * @type {?string} |
- */ |
- sitekeySource: null, |
- |
- /** |
- * @see ActiveFilter.sitekeys |
- */ |
get sitekeys() |
{ |
let sitekeys = null; |
if (this.sitekeySource) |
{ |
sitekeys = this.sitekeySource.split("|"); |
this.sitekeySource = null; |
} |
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 {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 |
@@ -705,17 +665,70 @@ |
if (this.contentType & typeMask && |
(this.thirdParty == null || this.thirdParty == thirdParty) && |
this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) |
{ |
return true; |
} |
return false; |
} |
-}); |
+} |
+ |
+exports.RegExpFilter = RegExpFilter; |
+ |
+/** |
+ * @see ActiveFilter.domainSourceIsUpperCase |
+ */ |
+RegExpFilter.prototype.domainSourceIsUpperCase = true; |
+ |
+/** |
+ * Number of filters contained, will always be 1 (required to |
+ * optimize Matcher). |
+ * @type {number} |
+ */ |
+RegExpFilter.prototype.length = 1; |
+ |
+/** |
+ * @see ActiveFilter.domainSeparator |
+ */ |
+RegExpFilter.prototype.domainSeparator = "|"; |
+ |
+/** |
+ * Expression from which a regular expression should be generated - |
+ * for delayed creation of the regexp property |
+ * @type {string} |
+ */ |
+RegExpFilter.prototype.regexpSource = null; |
+ |
+/** |
+ * Content types the filter applies to, combination of values from |
+ * RegExpFilter.typeMap |
+ * @type {number} |
+ */ |
+RegExpFilter.prototype.contentType = 0x7FFFFFFF; |
+ |
+/** |
+ * Defines whether the filter should distinguish between lower and |
+ * upper case letters |
+ * @type {boolean} |
+ */ |
+RegExpFilter.prototype.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} |
+ */ |
+RegExpFilter.prototype.thirdParty = null; |
+ |
+/** |
+ * String that the sitekey property should be generated from |
+ * @type {?string} |
+ */ |
+RegExpFilter.prototype.sitekeySource = null; |
// Required to optimize Matcher, see also RegExpFilter.prototype.length |
Object.defineProperty(RegExpFilter.prototype, "0", { |
get() { return this; } |
}); |
/** |
* Creates a RegExp filter from its text representation |
@@ -859,72 +872,55 @@ |
RegExpFilter.typeMap.DOCUMENT | |
RegExpFilter.typeMap.ELEMHIDE | |
RegExpFilter.typeMap.POPUP | |
RegExpFilter.typeMap.GENERICHIDE | |
RegExpFilter.typeMap.GENERICBLOCK); |
/** |
* Class for blocking filters |
- * @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 {string} [csp] |
- * Content Security Policy to inject when the filter matches |
- * @param {?string} [rewrite] |
- * The (optional) rule specifying how to rewrite the URL. See |
- * BlockingFilter.prototype.rewrite. |
- * @constructor |
- * @augments RegExpFilter |
*/ |
-function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys, collapse, csp, rewrite) |
+class BlockingFilter extends RegExpFilter |
{ |
- RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys); |
- |
- if (collapse != null) |
- this.collapse = collapse; |
+ /** |
+ * @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 {string} [csp] |
+ * Content Security Policy to inject when the filter matches |
+ * @param {?string} [rewrite] |
+ * The (optional) rule specifying how to rewrite the URL. See |
+ * BlockingFilter.prototype.rewrite. |
+ */ |
+ constructor(text, regexpSource, contentType, matchCase, domains, thirdParty, |
+ sitekeys, collapse, csp, rewrite) |
+ { |
+ super(text, regexpSource, contentType, matchCase, domains, thirdParty, |
+ sitekeys); |
- if (csp != null) |
- this.csp = csp; |
+ if (collapse != null) |
+ this.collapse = collapse; |
- if (rewrite != null) |
- this.rewrite = rewrite; |
-} |
-exports.BlockingFilter = BlockingFilter; |
- |
-BlockingFilter.prototype = extend(RegExpFilter, { |
- type: "blocking", |
+ if (csp != null) |
+ this.csp = csp; |
- /** |
- * Defines whether the filter should collapse blocked content. |
- * Can be null (use the global preference). |
- * @type {?boolean} |
- */ |
- collapse: null, |
+ if (rewrite != null) |
+ this.rewrite = rewrite; |
+ } |
- /** |
- * Content Security Policy to inject for matching requests. |
- * @type {?string} |
- */ |
- csp: null, |
- |
- /** |
- * The rule specifying how to rewrite the URL. |
- * The syntax is similar to the one of String.prototype.replace(). |
- * @type {?string} |
- */ |
- rewrite: null, |
+ get type() |
+ { |
+ return "blocking"; |
+ } |
/** |
* Rewrites an URL. |
* @param {string} url the URL to rewrite |
* @return {string} the rewritten URL, or the original in case of failure |
*/ |
rewriteUrl(url) |
{ |
@@ -935,73 +931,100 @@ |
return rewrittenUrl.href; |
} |
catch (e) |
{ |
} |
return url; |
} |
-}); |
+} |
+ |
+exports.BlockingFilter = BlockingFilter; |
+ |
+/** |
+ * Defines whether the filter should collapse blocked content. |
+ * Can be null (use the global preference). |
+ * @type {?boolean} |
+ */ |
+BlockingFilter.prototype.collapse = null; |
+ |
+/** |
+ * Content Security Policy to inject for matching requests. |
+ * @type {?string} |
+ */ |
+BlockingFilter.prototype.csp = null; |
+ |
+/** |
+ * The rule specifying how to rewrite the URL. |
+ * The syntax is similar to the one of String.prototype.replace(). |
+ * @type {?string} |
+ */ |
+BlockingFilter.prototype.rewrite = null; |
/** |
* Class for whitelist filters |
- * @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() |
- * @constructor |
- * @augments RegExpFilter |
*/ |
-function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys) |
+class WhitelistFilter extends RegExpFilter |
{ |
- RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys); |
+ /** |
+ * @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() |
+ */ |
+ constructor(text, regexpSource, contentType, matchCase, domains, thirdParty, |
+ sitekeys) |
+ { |
+ super(text, regexpSource, contentType, matchCase, domains, thirdParty, |
+ sitekeys); |
+ } |
+ |
+ get type() |
+ { |
+ return "whitelist"; |
+ } |
} |
+ |
exports.WhitelistFilter = WhitelistFilter; |
-WhitelistFilter.prototype = extend(RegExpFilter, { |
- type: "whitelist" |
-}); |
- |
/** |
* 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 |
- * @constructor |
- * @augments ActiveFilter |
*/ |
-function ElemHideBase(text, domains, selector) |
+class ElemHideBase extends ActiveFilter |
{ |
- ActiveFilter.call(this, text, domains || null); |
+ /** |
+ * @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(text, domains, selector) |
+ { |
+ super(text, domains || null); |
- // Braces are being escaped to prevent CSS rule injection. |
- this.selector = selector.replace("{", "\\7B ").replace("}", "\\7D "); |
+ /** |
+ * CSS selector for the HTML elements that should be hidden |
+ * @type {string} |
+ */ |
+ // Braces are being escaped to prevent CSS rule injection. |
+ this.selector = selector.replace("{", "\\7B ").replace("}", "\\7D "); |
+ } |
} |
+ |
exports.ElemHideBase = ElemHideBase; |
-ElemHideBase.prototype = extend(ActiveFilter, { |
- /** |
- * @see ActiveFilter.domainSeparator |
- */ |
- domainSeparator: ",", |
- |
- /** |
- * CSS selector for the HTML elements that should be hidden |
- * @type {string} |
- */ |
- selector: null |
-}); |
+/** |
+ * @see ActiveFilter.domainSeparator |
+ */ |
+ElemHideBase.prototype.domainSeparator = ","; |
/** |
* Creates an element hiding filter from a pre-parsed text representation |
* |
* @param {string} text same as in Filter() |
* @param {string} [domains] |
* domains part of the text representation |
* @param {string} [type] |
@@ -1031,59 +1054,74 @@ |
return new ElemHideEmulationFilter(text, domains, selector); |
} |
return new ElemHideFilter(text, domains, selector); |
}; |
/** |
* Class for element hiding filters |
- * @param {string} text see Filter() |
- * @param {string} [domains] see ElemHideBase() |
- * @param {string} selector see ElemHideBase() |
- * @constructor |
- * @augments ElemHideBase |
*/ |
-function ElemHideFilter(text, domains, selector) |
+class ElemHideFilter extends ElemHideBase |
{ |
- ElemHideBase.call(this, text, domains, selector); |
-} |
-exports.ElemHideFilter = ElemHideFilter; |
+ /** |
+ * @param {string} text see Filter() |
+ * @param {string} [domains] see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
+ */ |
+ constructor(text, domains, selector) |
+ { |
+ super(text, domains, selector); |
+ } |
-ElemHideFilter.prototype = extend(ElemHideBase, { |
- type: "elemhide" |
-}); |
+ get type() |
+ { |
+ return "elemhide"; |
+ } |
+} |
+ |
+exports.ElemHideFilter = ElemHideFilter; |
/** |
* Class for element hiding exceptions |
- * @param {string} text see Filter() |
- * @param {string} [domains] see ElemHideBase() |
- * @param {string} selector see ElemHideBase() |
- * @constructor |
- * @augments ElemHideBase |
*/ |
-function ElemHideException(text, domains, selector) |
+class ElemHideException extends ElemHideBase |
{ |
- ElemHideBase.call(this, text, domains, selector); |
-} |
-exports.ElemHideException = ElemHideException; |
+ /** |
+ * @param {string} text see Filter() |
+ * @param {string} [domains] see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
+ */ |
+ constructor(text, domains, selector) |
+ { |
+ super(text, domains, selector); |
+ } |
-ElemHideException.prototype = extend(ElemHideBase, { |
- type: "elemhideexception" |
-}); |
+ get type() |
+ { |
+ return "elemhideexception"; |
+ } |
+} |
+ |
+exports.ElemHideException = ElemHideException; |
/** |
* Class for element hiding emulation filters |
- * @param {string} text see Filter() |
- * @param {string} domains see ElemHideBase() |
- * @param {string} selector see ElemHideBase() |
- * @constructor |
- * @augments ElemHideBase |
*/ |
-function ElemHideEmulationFilter(text, domains, selector) |
+class ElemHideEmulationFilter extends ElemHideBase |
{ |
- ElemHideBase.call(this, text, domains, selector); |
-} |
-exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
+ /** |
+ * @param {string} text see Filter() |
+ * @param {string} domains see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
+ */ |
+ constructor(text, domains, selector) |
+ { |
+ super(text, domains, selector); |
+ } |
-ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
- type: "elemhideemulation" |
-}); |
+ get type() |
+ { |
+ return "elemhideemulation"; |
+ } |
+} |
+ |
+exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |