| 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 |
|
kzar
2018/01/08 15:29:35
Shouldn't this be `{?string}`?
hub
2018/01/08 16:29:51
The reference I use for JSDoc doesn't mention this
kzar
2018/01/08 16:56:06
Well the page you linked says this "@returns [{typ
hub
2018/01/08 17:53:13
Done
|
| + * 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 ", "}"); |
| + } |
| + 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); |
|
kzar
2018/01/08 15:35:01
Probably a dumb question, but how come with the Pr
hub
2018/01/08 16:29:51
PropsSelector search for the CSS properties using
hub
2018/01/10 06:05:17
The newer revision of the patch changed this as re
|
| + 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); |
| + }, |
| + |
| *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, |