| Index: lib/content/elemHideEmulation.js |
| =================================================================== |
| --- a/lib/content/elemHideEmulation.js |
| +++ b/lib/content/elemHideEmulation.js |
| @@ -166,16 +166,51 @@ |
| subtree.querySelector(selector); |
| } |
| function scopedQuerySelectorAll(subtree, selector) |
| { |
| return scopedQuerySelector(subtree, selector, true); |
| } |
| +const regexpRegexp = /^\/(.*)\/([im]*)$/; |
| + |
| +/** |
| + * Make a regular expression from a text argument. If it can be parsed as a |
| + * regular expression, parse it and the flags. |
| + * @param {string} text the text argument. |
| + * @param {boolean} escape indicate whether we escape curly braces. |
|
Manish Jethani
2018/02/20 10:47:10
escape could be made optional ("?boolean"), then t
hub
2018/02/20 17:50:18
Good point, but this is moot in the current patch.
|
| + * @param {?string} flags the regexp flags passed to the RegExp constructor: |
| + * it overrides flags passed in the text argument. |
| + * @return {?RegExp} a RegExp object or null in case of error. |
| + */ |
| +function makeRegExpParameter(text, escape, flags) |
| +{ |
| + let regexpString = null; |
| + let match = regexpRegexp.exec(text); |
| + if (match) |
| + { |
| + regexpString = |
| + escape ? match[1].replace("\\7B ", "{").replace("\\7D ", "}") : match[1]; |
| + if (!flags) |
| + flags = match[2]; |
| + } |
| + else |
| + regexpString = filterToRegExp(text); |
|
Manish Jethani
2018/02/20 10:47:10
This doesn't make sense for the contains filter, d
hub
2018/02/20 17:50:18
You are totally right. The new patch fixes that.
|
| + |
| + try |
| + { |
| + return new RegExp(regexpString, flags); |
| + } |
| + catch (e) |
| + { |
| + } |
| + return null; |
| +} |
| + |
| function* evaluate(chain, index, prefix, subtree, styles) |
| { |
| if (index >= chain.length) |
| { |
| yield prefix; |
| return; |
| } |
| for (let [selector, element] of |
| @@ -258,17 +293,17 @@ |
| yield null; |
| } |
| } |
| } |
| }; |
| function ContainsSelector(textContent) |
| { |
| - this._text = textContent; |
| + this._regexp = makeRegExpParameter(textContent, false); |
| } |
| ContainsSelector.prototype = { |
| requiresHiding: true, |
| *getSelectors(prefix, subtree, stylesheet) |
| { |
| for (let element of this.getElements(prefix, subtree, stylesheet)) |
| @@ -280,48 +315,38 @@ |
| let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| prefix + "*" : prefix; |
| let elements = scopedQuerySelectorAll(subtree, actualPrefix); |
| if (elements) |
| { |
| 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, true, "i"); |
| } |
| PropsSelector.prototype = { |
| preferHideWithSelector: true, |
| dependsOnStyles: true, |
| *findPropsSelectors(styles, prefix, regexp) |
| { |
| for (let style of styles) |
| - if (regexp.test(style.style)) |
| + if (regexp && regexp.test(style.style)) |
| for (let subSelector of style.subSelectors) |
| { |
| if (subSelector.startsWith("*") && |
| !incompletePrefixRegexp.test(prefix)) |
| { |
| subSelector = subSelector.substr(1); |
| } |
| let idx = subSelector.lastIndexOf("::"); |