| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 let priority = rule.style.getPropertyPriority(property); | 115 let priority = rule.style.getPropertyPriority(property); |
| 116 styles.push(`${property}: ${value}${priority ? " !" + priority : ""};`); | 116 styles.push(`${property}: ${value}${priority ? " !" + priority : ""};`); |
| 117 } | 117 } |
| 118 styles.sort(); | 118 styles.sort(); |
| 119 return { | 119 return { |
| 120 style: styles.join(" "), | 120 style: styles.join(" "), |
| 121 subSelectors: splitSelector(rule.selectorText) | 121 subSelectors: splitSelector(rule.selectorText) |
| 122 }; | 122 }; |
| 123 } | 123 } |
| 124 | 124 |
| 125 /** | |
| 126 * Check if a text argument is a regexp. | |
| 127 * @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.
| |
| 128 * @return {?string} an unescaped RegExp string. null if it is not a | |
| 129 * regexp, ie not surrounded by '/'. | |
| 130 */ | |
| 131 function checkRegExpParameter(text) | |
| 132 { | |
| 133 let regexpString = null; | |
| 134 if (text.length >= 2 && text[0] == "/" && | |
| 135 text[text.length - 1] == "/") | |
| 136 { | |
| 137 regexpString = text.slice(1, -1) | |
| 138 .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
| |
| 139 } | |
| 140 return regexpString; | |
| 141 } | |
| 142 | |
| 125 function* evaluate(chain, index, prefix, subtree, styles) | 143 function* evaluate(chain, index, prefix, subtree, styles) |
| 126 { | 144 { |
| 127 if (index >= chain.length) | 145 if (index >= chain.length) |
| 128 { | 146 { |
| 129 yield prefix; | 147 yield prefix; |
| 130 return; | 148 return; |
| 131 } | 149 } |
| 132 for (let [selector, element] of | 150 for (let [selector, element] of |
| 133 chain[index].getSelectors(prefix, subtree, styles)) | 151 chain[index].getSelectors(prefix, subtree, styles)) |
| 134 { | 152 { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 // :scope isn't supported on Edge, ignore error caused by it. | 235 // :scope isn't supported on Edge, ignore error caused by it. |
| 218 } | 236 } |
| 219 } | 237 } |
| 220 yield null; | 238 yield null; |
| 221 } | 239 } |
| 222 } | 240 } |
| 223 }; | 241 }; |
| 224 | 242 |
| 225 function ContainsSelector(textContent) | 243 function ContainsSelector(textContent) |
| 226 { | 244 { |
| 227 this._text = textContent; | 245 let regexpString = checkRegExpParameter(textContent); |
| 246 if (regexpString) | |
| 247 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,
| |
| 248 else | |
| 249 this._text = textContent; | |
| 228 } | 250 } |
| 229 | 251 |
| 230 ContainsSelector.prototype = { | 252 ContainsSelector.prototype = { |
| 231 requiresHiding: true, | 253 requiresHiding: true, |
| 232 | 254 |
| 255 match(element) | |
| 256 { | |
| 257 if (this._regexp) | |
| 258 return this._regexp.test(element.textContent); | |
| 259 | |
| 260 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
| |
| 261 }, | |
| 262 | |
| 233 *getSelectors(prefix, subtree, stylesheet) | 263 *getSelectors(prefix, subtree, stylesheet) |
| 234 { | 264 { |
| 235 for (let element of this.getElements(prefix, subtree, stylesheet)) | 265 for (let element of this.getElements(prefix, subtree, stylesheet)) |
| 236 yield [makeSelector(element, ""), subtree]; | 266 yield [makeSelector(element, ""), subtree]; |
| 237 }, | 267 }, |
| 238 | 268 |
| 239 *getElements(prefix, subtree, stylesheet) | 269 *getElements(prefix, subtree, stylesheet) |
| 240 { | 270 { |
| 241 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 271 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| 242 prefix + "*" : prefix; | 272 prefix + "*" : prefix; |
| 243 let elements = subtree.querySelectorAll(actualPrefix); | 273 let elements = subtree.querySelectorAll(actualPrefix); |
| 244 | 274 |
| 245 for (let element of elements) | 275 for (let element of elements) |
| 246 { | 276 { |
| 247 if (element.textContent.includes(this._text)) | 277 if (this.match(element)) |
| 248 yield element; | 278 yield element; |
| 249 else | 279 else |
| 250 yield null; | 280 yield null; |
| 251 } | 281 } |
| 252 } | 282 } |
| 253 }; | 283 }; |
| 254 | 284 |
| 255 function PropsSelector(propertyExpression) | 285 function PropsSelector(propertyExpression) |
| 256 { | 286 { |
| 257 let regexpString; | 287 let regexpString = checkRegExpParameter(propertyExpression); |
| 258 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 288 if (!regexpString) |
| 259 propertyExpression[propertyExpression.length - 1] == "/") | |
| 260 { | |
| 261 regexpString = propertyExpression.slice(1, -1) | |
| 262 .replace("\\7B ", "{").replace("\\7D ", "}"); | |
| 263 } | |
| 264 else | |
| 265 regexpString = filterToRegExp(propertyExpression); | 289 regexpString = filterToRegExp(propertyExpression); |
| 266 | 290 |
| 267 this._regexp = new RegExp(regexpString, "i"); | 291 this._regexp = new RegExp(regexpString, "i"); |
| 268 } | 292 } |
| 269 | 293 |
| 270 PropsSelector.prototype = { | 294 PropsSelector.prototype = { |
| 271 preferHideWithSelector: true, | 295 preferHideWithSelector: true, |
| 272 dependsOnStyles: true, | 296 dependsOnStyles: true, |
| 273 | 297 |
| 274 *findPropsSelectors(styles, prefix, regexp) | 298 *findPropsSelectors(styles, prefix, regexp) |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 characterData: true, | 628 characterData: true, |
| 605 subtree: true | 629 subtree: true |
| 606 } | 630 } |
| 607 ); | 631 ); |
| 608 this.document.addEventListener("load", this.onLoad.bind(this), true); | 632 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 609 } | 633 } |
| 610 } | 634 } |
| 611 }; | 635 }; |
| 612 | 636 |
| 613 exports.ElemHideEmulation = ElemHideEmulation; | 637 exports.ElemHideEmulation = ElemHideEmulation; |
| OLD | NEW |