| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 /** | 187 /** | 
| 188 * Generator function returning selected elements. | 188 * Generator function returning selected elements. | 
| 189 * @param {string} prefix the prefix for the selector. | 189 * @param {string} prefix the prefix for the selector. | 
| 190 * @param {Node} subtree the subtree we work on. | 190 * @param {Node} subtree the subtree we work on. | 
| 191 * @param {StringifiedStyle[]} styles the stringified style objects. | 191 * @param {StringifiedStyle[]} styles the stringified style objects. | 
| 192 */ | 192 */ | 
| 193 *getElements(prefix, subtree, styles) | 193 *getElements(prefix, subtree, styles) | 
| 194 { | 194 { | 
| 195 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 195 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 
| 196 prefix + "*" : prefix; | 196 prefix + "*" : prefix; | 
| 197 let elements = subtree.querySelectorAll(actualPrefix); | 197 if (relativeSelectorRegexp.test(actualPrefix)) | 
| 
 
Manish Jethani
2018/01/23 16:42:11
If I understand this correctly, "+" and "~" don't
 
hub
2018/01/25 21:58:34
Done.
 
 | |
| 198 for (let element of elements) | 198 actualPrefix = ":scope" + actualPrefix; | 
| 199 try | |
| 199 { | 200 { | 
| 200 let iter = evaluate(this._innerSelectors, 0, "", element, styles); | 201 let elements = subtree.querySelectorAll(actualPrefix); | 
| 
 
lainverse
2018/01/23 01:02:51
As I understand if this fails it's still possible
 
Manish Jethani
2018/01/23 16:42:11
I agree this could probably be made to work on Edg
 
hub
2018/01/23 16:51:11
Filed https://issues.adblockplus.org/ticket/6304
 
 | |
| 201 for (let selector of iter) | 202 for (let element of elements) | 
| 202 { | 203 { | 
| 203 if (selector == null) | 204 let iter = evaluate(this._innerSelectors, 0, "", element, styles); | 
| 205 for (let selector of iter) | |
| 204 { | 206 { | 
| 205 yield null; | 207 if (selector == null) | 
| 206 continue; | 208 { | 
| 209 yield null; | |
| 210 continue; | |
| 211 } | |
| 212 if (relativeSelectorRegexp.test(selector)) | |
| 
 
Manish Jethani
2018/01/23 16:42:11
So this and the try..catch could be made generic a
 
hub
2018/01/25 21:58:34
This should allow us to fix issue #6304 more easil
 
 | |
| 213 selector = ":scope" + selector; | |
| 214 try | |
| 215 { | |
| 216 if (element.querySelector(selector)) | |
| 217 yield element; | |
| 218 } | |
| 219 catch (e) | |
| 220 { | |
| 221 // :scope isn't supported on Edge, ignore error caused by it. | |
| 222 } | |
| 207 } | 223 } | 
| 208 if (relativeSelectorRegexp.test(selector)) | 224 yield null; | 
| 209 selector = ":scope" + selector; | |
| 210 try | |
| 211 { | |
| 212 if (element.querySelector(selector)) | |
| 213 yield element; | |
| 214 } | |
| 215 catch (e) | |
| 216 { | |
| 217 // :scope isn't supported on Edge, ignore error caused by it. | |
| 218 } | |
| 219 } | 225 } | 
| 220 yield null; | 226 } | 
| 227 catch (e) | |
| 228 { | |
| 229 // :scope isn't supported on Edge, ignore error caused by it. | |
| 221 } | 230 } | 
| 222 } | 231 } | 
| 223 }; | 232 }; | 
| 224 | 233 | 
| 225 function ContainsSelector(textContent) | 234 function ContainsSelector(textContent) | 
| 226 { | 235 { | 
| 227 this._text = textContent; | 236 this._text = textContent; | 
| 228 } | 237 } | 
| 229 | 238 | 
| 230 ContainsSelector.prototype = { | 239 ContainsSelector.prototype = { | 
| 231 requiresHiding: true, | 240 requiresHiding: true, | 
| 232 | 241 | 
| 233 *getSelectors(prefix, subtree, stylesheet) | 242 *getSelectors(prefix, subtree, stylesheet) | 
| 234 { | 243 { | 
| 235 for (let element of this.getElements(prefix, subtree, stylesheet)) | 244 for (let element of this.getElements(prefix, subtree, stylesheet)) | 
| 236 yield [makeSelector(element, ""), subtree]; | 245 yield [makeSelector(element, ""), subtree]; | 
| 237 }, | 246 }, | 
| 238 | 247 | 
| 239 *getElements(prefix, subtree, stylesheet) | 248 *getElements(prefix, subtree, stylesheet) | 
| 240 { | 249 { | 
| 241 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 250 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 
| 242 prefix + "*" : prefix; | 251 prefix + "*" : prefix; | 
| 243 let elements = subtree.querySelectorAll(actualPrefix); | 252 if (relativeSelectorRegexp.test(actualPrefix)) | 
| 253 actualPrefix = ":scope" + actualPrefix; | |
| 254 try | |
| 255 { | |
| 256 let elements = subtree.querySelectorAll(actualPrefix); | |
| 244 | 257 | 
| 245 for (let element of elements) | 258 for (let element of elements) | 
| 259 { | |
| 260 if (element.textContent.includes(this._text)) | |
| 261 yield element; | |
| 262 else | |
| 263 yield null; | |
| 264 } | |
| 265 } | |
| 266 catch (e) | |
| 246 { | 267 { | 
| 247 if (element.textContent.includes(this._text)) | 268 // :scope isn't supported on Edge, ignore error caused by it. | 
| 248 yield element; | |
| 249 else | |
| 250 yield null; | |
| 251 } | 269 } | 
| 252 } | 270 } | 
| 253 }; | 271 }; | 
| 254 | 272 | 
| 255 function PropsSelector(propertyExpression) | 273 function PropsSelector(propertyExpression) | 
| 256 { | 274 { | 
| 257 let regexpString; | 275 let regexpString; | 
| 258 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 276 if (propertyExpression.length >= 2 && propertyExpression[0] == "/" && | 
| 259 propertyExpression[propertyExpression.length - 1] == "/") | 277 propertyExpression[propertyExpression.length - 1] == "/") | 
| 260 { | 278 { | 
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 characterData: true, | 622 characterData: true, | 
| 605 subtree: true | 623 subtree: true | 
| 606 } | 624 } | 
| 607 ); | 625 ); | 
| 608 this.document.addEventListener("load", this.onLoad.bind(this), true); | 626 this.document.addEventListener("load", this.onLoad.bind(this), true); | 
| 609 } | 627 } | 
| 610 } | 628 } | 
| 611 }; | 629 }; | 
| 612 | 630 | 
| 613 exports.ElemHideEmulation = ElemHideEmulation; | 631 exports.ElemHideEmulation = ElemHideEmulation; | 
| OLD | NEW |