Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -82,17 +82,17 @@ |
* @type {Object} |
*/ |
Filter.knownFilters = Object.create(null); |
/** |
* Regular expression that element hiding filters should match |
* @type {RegExp} |
*/ |
-Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/; |
+Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?^])?#(.+)$/; |
/** |
* Regular expression that RegExp filters specified as RegExps should match |
* @type {RegExp} |
*/ |
Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)?$/; |
/** |
* Regular expression that options on a RegExp filter should match |
* @type {RegExp} |
@@ -943,43 +943,63 @@ |
* |
* @param {string} text same as in Filter() |
* @param {string?} domain |
* domain part of the text representation |
* @param {string?} type |
* rule type, either empty or @ (exception) or ? (emulation rule) |
* @param {string} selector raw CSS selector |
* @return {ElemHideFilter|ElemHideException| |
- * ElemHideEmulationFilter|InvalidFilter} |
+ * ElemHideEmulationFilter|ElemHideEmulationException|InvalidFilter} |
*/ |
ElemHideBase.fromText = function(text, domain, type, selector) |
{ |
// We don't allow ElemHide filters which have any empty domains. |
// Note: The ElemHide.prototype.domainSeparator is duplicated here, if that |
// changes this must be changed too. |
if (domain && /(^|,)~?(,|$)/.test(domain)) |
return new InvalidFilter(text, "filter_invalid_domain"); |
if (type == "@") |
return new ElemHideException(text, domain, selector); |
- if (type == "?") |
+ if ((type == "?") || (type == "^")) |
{ |
// Element hiding emulation filters are inefficient so we need to make sure |
// that they're only applied if they specify active domains |
if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); |
+ if (type == "^") |
+ return new ElemHideEmulationException(text, domain, selector); |
+ |
return new ElemHideEmulationFilter(text, domain, selector); |
} |
return new ElemHideFilter(text, domain, selector); |
}; |
/** |
+ * Base class for element hiding exceptions |
+ * @param {string} text see Filter() |
+ * @param {string} domains see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
+ * @constructor |
+ * @augments ElemHideBase |
+ */ |
+function ElemHideExceptionBase(text, domains, selector) |
+{ |
+ ElemHideBase.call(this, text, domains, selector); |
+} |
+exports.ElemHideExceptionBase = ElemHideExceptionBase; |
+ |
+ElemHideExceptionBase.prototype = extend(ElemHideBase, { |
+}); |
+ |
+/** |
* 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) |
@@ -993,25 +1013,25 @@ |
}); |
/** |
* Class for element hiding exceptions |
* @param {string} text see Filter() |
* @param {string} domains see ElemHideBase() |
* @param {string} selector see ElemHideBase() |
* @constructor |
- * @augments ElemHideBase |
+ * @augments ElemHideExceptionBase |
*/ |
function ElemHideException(text, domains, selector) |
{ |
- ElemHideBase.call(this, text, domains, selector); |
+ ElemHideExceptionBase.call(this, text, domains, selector); |
} |
exports.ElemHideException = ElemHideException; |
-ElemHideException.prototype = extend(ElemHideBase, { |
+ElemHideException.prototype = extend(ElemHideExceptionBase, { |
type: "elemhideexception" |
}); |
/** |
* Class for element hiding emulation filters |
* @param {string} text see Filter() |
* @param {string} domains see ElemHideBase() |
* @param {string} selector see ElemHideBase() |
@@ -1022,8 +1042,26 @@ |
{ |
ElemHideBase.call(this, text, domains, selector); |
} |
exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
type: "elemhideemulation" |
}); |
+ |
+/** |
+ * Class for element hiding emulation exceptions |
+ * @param {string} text see Filter() |
+ * @param {string} domains see ElemHideBase() |
+ * @param {string} selector see ElemHideBase() |
+ * @constructor |
+ * @augments ElemHideExceptionBase |
+ */ |
+function ElemHideEmulationException(text, domains, selector) |
+{ |
+ ElemHideExceptionBase.call(this, text, domains, selector); |
+} |
+exports.ElemHideEmulationException = ElemHideEmulationException; |
+ |
+ElemHideEmulationException.prototype = extend(ElemHideExceptionBase, { |
+ type: "elemhideemulationexception" |
+}); |