LEFT | RIGHT |
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 relativeSelector = /^[>+~]/; | 192 const relativeSelectorRegexp = /^[>+~]/; |
193 | 193 |
194 function HasSelector(selectors) | 194 function HasSelector(selectors) |
195 { | 195 { |
196 this._innerSelectors = selectors; | 196 this._innerSelectors = selectors; |
197 } | 197 } |
198 | 198 |
199 HasSelector.prototype = { | 199 HasSelector.prototype = { |
200 requiresHiding: true, | 200 requiresHiding: true, |
201 | 201 |
202 get dependsOnStyles() | 202 get dependsOnStyles() |
(...skipping 16 matching lines...) Expand all Loading... |
219 *getElements(prefix, subtree, styles) | 219 *getElements(prefix, subtree, styles) |
220 { | 220 { |
221 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? | 221 let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
222 prefix + "*" : prefix; | 222 prefix + "*" : prefix; |
223 let elements = subtree.querySelectorAll(actualPrefix); | 223 let elements = subtree.querySelectorAll(actualPrefix); |
224 for (let element of elements) | 224 for (let element of elements) |
225 { | 225 { |
226 let iter = evaluate(this._innerSelectors, 0, "", element, styles); | 226 let iter = evaluate(this._innerSelectors, 0, "", element, styles); |
227 for (let selector of iter) | 227 for (let selector of iter) |
228 { | 228 { |
229 // :scope isn't supported on Edge. It still is not standard. | 229 if (relativeSelectorRegexp.test(selector)) |
230 if (relativeSelector.test(selector)) | |
231 selector = ":scope" + selector; | 230 selector = ":scope" + selector; |
232 try | 231 try |
233 { | 232 { |
234 if (element.querySelector(selector)) | 233 if (element.querySelector(selector)) |
235 yield element; | 234 yield element; |
236 } | 235 } |
237 catch (e) | 236 catch (e) |
238 { | 237 { |
| 238 // :scope isn't supported on Edge, ignore error caused by it. |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 }; | 243 }; |
244 | 244 |
245 function ContainsSelector(textContent) | 245 function ContainsSelector(textContent) |
246 { | 246 { |
247 this._text = textContent; | 247 this._text = textContent; |
248 } | 248 } |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 517 |
518 if (this.patterns.length > 0) | 518 if (this.patterns.length > 0) |
519 { | 519 { |
520 let {document} = this.window; | 520 let {document} = this.window; |
521 this.addSelectors(); | 521 this.addSelectors(); |
522 document.addEventListener("load", this.onLoad.bind(this), true); | 522 document.addEventListener("load", this.onLoad.bind(this), true); |
523 } | 523 } |
524 }); | 524 }); |
525 } | 525 } |
526 }; | 526 }; |
LEFT | RIGHT |