Index: lib/content/elemHideEmulation.js |
=================================================================== |
--- a/lib/content/elemHideEmulation.js |
+++ b/lib/content/elemHideEmulation.js |
@@ -117,16 +117,34 @@ |
} |
styles.sort(); |
return { |
style: styles.join(" "), |
subSelectors: splitSelector(rule.selectorText) |
}; |
} |
+/** |
+ * Check if a text argument is a regexp. |
+ * @param {string} text argument. |
+ * @return {string} an unescaped RegExp string. null if it is not a |
+ * regexp, ie not surrounded by '/'. |
+ */ |
+function checkRegExpParameter(text) |
+{ |
+ let regexpString = null; |
+ if (text.length >= 2 && text[0] == "/" && |
lainverse
2017/11/22 09:06:19
Technically // is not a valid regexp, even though
hub
2017/11/22 14:34:59
this is just what was done before for :-abp-proper
|
+ text[text.length - 1] == "/") |
+ { |
+ regexpString = text.slice(1, -1) |
+ .replace("\\7B ", "{").replace("\\7D ", "}"); |
+ } |
+ return regexpString; |
+} |
+ |
function* evaluate(chain, index, prefix, subtree, styles) |
{ |
if (index >= chain.length) |
{ |
yield prefix; |
return; |
} |
for (let [selector, element] of |
@@ -219,54 +237,60 @@ |
} |
yield null; |
} |
} |
}; |
function ContainsSelector(textContent) |
{ |
- this._text = textContent; |
+ let regexpString = checkRegExpParameter(textContent); |
+ if (regexpString) |
+ this._regexp = new RegExp(regexpString); |
+ else |
+ this._text = textContent; |
} |
ContainsSelector.prototype = { |
requiresHiding: true, |
+ match(element) |
+ { |
+ if (this._regexp) |
+ return element.textContent.match(this._regexp); |
lainverse
2017/11/22 09:06:19
Might be better to use this._regexp.test() since i
hub
2017/11/22 14:34:59
good point.
|
+ |
+ return element.textContent.includes(this._text); |
+ }, |
+ |
*getSelectors(prefix, subtree, stylesheet) |
{ |
for (let element of this.getElements(prefix, subtree, stylesheet)) |
yield [makeSelector(element, ""), subtree]; |
}, |
*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.match(element)) |
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 |
+ let regexpString = checkRegExpParameter(propertyExpression); |
+ if (!regexpString) |
regexpString = filterToRegExp(propertyExpression); |
this._regexp = new RegExp(regexpString, "i"); |
} |
PropsSelector.prototype = { |
preferHideWithSelector: true, |
dependsOnStyles: true, |