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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 * @param {Node} subtree the subtree we work on. | 182 * @param {Node} subtree the subtree we work on. |
183 * @param {StringifiedStyle[]} styles the stringified style objects. | 183 * @param {StringifiedStyle[]} styles the stringified style objects. |
184 */ | 184 */ |
185 *getSelectors(prefix, subtree, styles) | 185 *getSelectors(prefix, subtree, styles) |
186 { | 186 { |
187 yield [prefix + this._selector, subtree]; | 187 yield [prefix + this._selector, subtree]; |
188 } | 188 } |
189 }; | 189 }; |
190 | 190 |
191 const incompletePrefixRegexp = /[\s>+~]$/; | 191 const incompletePrefixRegexp = /[\s>+~]$/; |
| 192 const relativeSelectorRegexp = /^[>+~]/; |
192 | 193 |
193 function HasSelector(selectors) | 194 function HasSelector(selectors) |
194 { | 195 { |
195 this._innerSelectors = selectors; | 196 this._innerSelectors = selectors; |
196 } | 197 } |
197 | 198 |
198 HasSelector.prototype = { | 199 HasSelector.prototype = { |
199 requiresHiding: true, | 200 requiresHiding: true, |
200 | 201 |
201 get dependsOnStyles() | 202 get dependsOnStyles() |
(...skipping 15 matching lines...) Expand all Loading... |
217 */ | 218 */ |
218 *getElements(prefix, subtree, styles) | 219 *getElements(prefix, subtree, styles) |
219 { | 220 { |
220 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 221 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
221 prefix + "*" : prefix; | 222 prefix + "*" : prefix; |
222 let elements = subtree.querySelectorAll(actualPrefix); | 223 let elements = subtree.querySelectorAll(actualPrefix); |
223 for (let element of elements) | 224 for (let element of elements) |
224 { | 225 { |
225 let iter = evaluate(this._innerSelectors, 0, "", element, styles); | 226 let iter = evaluate(this._innerSelectors, 0, "", element, styles); |
226 for (let selector of iter) | 227 for (let selector of iter) |
227 if (element.querySelector(selector)) | 228 { |
228 yield element; | 229 if (relativeSelectorRegexp.test(selector)) |
| 230 selector = ":scope" + selector; |
| 231 try |
| 232 { |
| 233 if (element.querySelector(selector)) |
| 234 yield element; |
| 235 } |
| 236 catch (e) |
| 237 { |
| 238 // :scope isn't supported on Edge, ignore error caused by it. |
| 239 } |
| 240 } |
229 } | 241 } |
230 } | 242 } |
231 }; | 243 }; |
232 | 244 |
233 function ContainsSelector(textContent) | 245 function ContainsSelector(textContent) |
234 { | 246 { |
235 this._text = textContent; | 247 this._text = textContent; |
236 } | 248 } |
237 | 249 |
238 ContainsSelector.prototype = { | 250 ContainsSelector.prototype = { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 517 |
506 if (this.patterns.length > 0) | 518 if (this.patterns.length > 0) |
507 { | 519 { |
508 let {document} = this.window; | 520 let {document} = this.window; |
509 this.addSelectors(); | 521 this.addSelectors(); |
510 document.addEventListener("load", this.onLoad.bind(this), true); | 522 document.addEventListener("load", this.onLoad.bind(this), true); |
511 } | 523 } |
512 }); | 524 }); |
513 } | 525 } |
514 }; | 526 }; |
OLD | NEW |