Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -16,32 +16,31 @@ |
*/ |
"use strict"; |
/** |
* @fileOverview Definition of Filter class and its subclasses. |
*/ |
-const {FilterNotifier} = require("./filterNotifier"); |
-const {extend} = require("./coreUtils"); |
-const {filterToRegExp} = require("./common"); |
+import {FilterNotifier} from "./filterNotifier"; |
+import {extend} from "./coreUtils"; |
+import {filterToRegExp} from "./common"; |
/** |
* Abstract base class for filters |
* |
* @param {string} text string representation of the filter |
* @constructor |
*/ |
-function Filter(text) |
+export function Filter(text) |
{ |
this.text = text; |
this.subscriptions = []; |
} |
-exports.Filter = Filter; |
Filter.prototype = |
{ |
/** |
* String representation of the filter |
* @type {string} |
*/ |
text: null, |
@@ -197,23 +196,22 @@ |
/** |
* 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) |
+export function InvalidFilter(text, reason) |
{ |
Filter.call(this, text); |
this.reason = reason; |
} |
-exports.InvalidFilter = InvalidFilter; |
InvalidFilter.prototype = extend(Filter, { |
type: "invalid", |
/** |
* Reason why this filter is invalid |
* @type {string} |
*/ |
@@ -227,21 +225,20 @@ |
}); |
/** |
* Class for comments |
* @param {string} text see Filter() |
* @constructor |
* @augments Filter |
*/ |
-function CommentFilter(text) |
+export function CommentFilter(text) |
{ |
Filter.call(this, text); |
} |
-exports.CommentFilter = CommentFilter; |
CommentFilter.prototype = extend(Filter, { |
type: "comment", |
/** |
* See Filter.serialize() |
* @inheritdoc |
*/ |
@@ -253,23 +250,22 @@ |
* @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) |
+export function ActiveFilter(text, domains) |
{ |
Filter.call(this, text); |
this.domainSource = domains; |
} |
-exports.ActiveFilter = ActiveFilter; |
ActiveFilter.prototype = extend(Filter, { |
_disabled: false, |
_hitCount: 0, |
_lastHit: 0, |
/** |
* Defines whether the filter is disabled |
@@ -550,18 +546,18 @@ |
* @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) |
+export function RegExpFilter(text, regexpSource, contentType, matchCase, |
+ domains, thirdParty, sitekeys) |
{ |
ActiveFilter.call(this, text, domains, sitekeys); |
if (contentType != null) |
this.contentType = contentType; |
if (matchCase) |
this.matchCase = matchCase; |
if (thirdParty != null) |
@@ -580,17 +576,16 @@ |
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; |
RegExpFilter.prototype = extend(ActiveFilter, { |
/** |
* @see ActiveFilter.domainSourceIsUpperCase |
*/ |
domainSourceIsUpperCase: true, |
/** |
@@ -838,25 +833,24 @@ |
* @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) |
+export function BlockingFilter(text, regexpSource, contentType, matchCase, |
+ domains, thirdParty, sitekeys, collapse) |
{ |
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
thirdParty, sitekeys); |
this.collapse = collapse; |
} |
-exports.BlockingFilter = BlockingFilter; |
BlockingFilter.prototype = extend(RegExpFilter, { |
type: "blocking", |
/** |
* Defines whether the filter should collapse blocked content. |
* Can be null (use the global preference). |
* @type {boolean} |
@@ -871,52 +865,50 @@ |
* @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) |
+export function WhitelistFilter(text, regexpSource, contentType, matchCase, |
+ domains, thirdParty, sitekeys) |
{ |
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
thirdParty, sitekeys); |
} |
-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) |
+export function ElemHideBase(text, domains, selector) |
{ |
ActiveFilter.call(this, text, domains || null); |
if (domains) |
{ |
this.selectorDomain = domains.replace(/,~[^,]+/g, "") |
.replace(/^~[^,]+,?/, "").toLowerCase(); |
} |
// 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: ",", |
/** |
@@ -980,49 +972,46 @@ |
* @param {string} selector see ElemHideBase() |
* @constructor |
* @augments ElemHideBase |
*/ |
function ElemHideFilter(text, domains, selector) |
{ |
ElemHideBase.call(this, text, domains, selector); |
} |
-exports.ElemHideFilter = ElemHideFilter; |
ElemHideFilter.prototype = extend(ElemHideBase, { |
type: "elemhide" |
}); |
/** |
* 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) |
+export function ElemHideException(text, domains, selector) |
{ |
ElemHideBase.call(this, text, domains, selector); |
} |
-exports.ElemHideException = ElemHideException; |
ElemHideException.prototype = extend(ElemHideBase, { |
type: "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) |
+export function ElemHideEmulationFilter(text, domains, selector) |
{ |
ElemHideBase.call(this, text, domains, selector); |
} |
-exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
type: "elemhideemulation" |
}); |