Index: lib/content/elemHideEmulation.js |
=================================================================== |
--- a/lib/content/elemHideEmulation.js |
+++ b/lib/content/elemHideEmulation.js |
@@ -117,16 +117,37 @@ |
} |
styles.sort(); |
return { |
style: styles.join(" "), |
subSelectors: splitSelector(rule.selectorText) |
}; |
} |
+/** |
+ * Make a regular expresson from a text argument. |
+ * @param {string} text the text argument. |
+ * @param {?string} flag the regexp flag passed to the RegExp constructor. |
+ * @return {RegExp} a RegExp object. |
+ */ |
+function makeRegExpParameter(text, flag) |
+{ |
+ let regexpString = null; |
+ if (text.length >= 2 && text[0] == "/" && |
+ text[text.length - 1] == "/") |
+ { |
+ regexpString = text.slice(1, -1) |
+ .replace("\\7B ", "{").replace("\\7D ", "}"); |
+ } |
+ else |
+ regexpString = filterToRegExp(text); |
+ |
+ return new RegExp(regexpString, flag); |
+} |
+ |
function* evaluate(chain, index, prefix, subtree, styles) |
{ |
if (index >= chain.length) |
{ |
yield prefix; |
return; |
} |
for (let [selector, element] of |
@@ -219,17 +240,17 @@ |
} |
yield null; |
} |
} |
}; |
function ContainsSelector(textContent) |
{ |
- this._text = textContent; |
+ this._regexp = makeRegExpParameter(textContent); |
} |
ContainsSelector.prototype = { |
requiresHiding: true, |
*getSelectors(prefix, subtree, stylesheet) |
{ |
for (let element of this.getElements(prefix, subtree, stylesheet)) |
@@ -239,37 +260,27 @@ |
*getElements(prefix, subtree, stylesheet) |
{ |
let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
prefix + "*" : prefix; |
let elements = subtree.querySelectorAll(actualPrefix); |
for (let element of elements) |
{ |
- if (element.textContent.includes(this._text)) |
+ if (this._regexp && this._regexp.test(element.textContent)) |
yield element; |
else |
yield null; |
} |
} |
}; |
function PropsSelector(propertyExpression) |
{ |
- let regexpString; |
- if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && |
- propertyExpression[propertyExpression.length - 1] == "/") |
- { |
- regexpString = propertyExpression.slice(1, -1) |
- .replace("\\7B ", "{").replace("\\7D ", "}"); |
- } |
- else |
- regexpString = filterToRegExp(propertyExpression); |
- |
- this._regexp = new RegExp(regexpString, "i"); |
+ this._regexp = makeRegExpParameter(propertyExpression, "i"); |
} |
PropsSelector.prototype = { |
preferHideWithSelector: true, |
dependsOnStyles: true, |
*findPropsSelectors(styles, prefix, regexp) |
{ |