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. |
Manish Jethani
2018/01/09 07:53:02
This should be:
@param {string} text the text a
hub
2018/01/09 18:33:06
Done.
|
+ * @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] == "/" && |
+ text[text.length - 1] == "/") |
+ { |
+ regexpString = text.slice(1, -1) |
+ .replace("\\7B ", "{").replace("\\7D ", "}"); |
Manish Jethani
2018/01/09 07:53:02
Why is this needed? If it's for legacy reasons, ma
hub
2018/01/09 18:33:06
We still want to have a valid CSS selector syntax.
Manish Jethani
2018/01/10 11:22:14
Acknowledged.
Manish Jethani
2018/01/16 12:00:22
Why does this have to be valid CSS selector syntax
|
+ } |
+ 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); |
Manish Jethani
2018/01/09 07:53:02
We have to consider what happens if the regular ex
lainverse
2018/01/09 10:49:22
I think it should be either "RegExp(regexpString,
|
+ else |
+ this._text = textContent; |
} |
ContainsSelector.prototype = { |
requiresHiding: true, |
+ match(element) |
+ { |
+ if (this._regexp) |
+ return this._regexp.test(element.textContent); |
+ |
+ return element.textContent.includes(this._text); |
lainverse
2018/01/09 10:49:22
I wasn't quite sure that "string.includes()" actua
hub
2018/01/09 18:33:06
I'll rewrite this part taking the comments above i
|
+ }, |
+ |
*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, |