| Left: | ||
| Right: |
| 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-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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 { | 128 { |
| 129 let elements = null; | 129 let elements = null; |
| 130 try | 130 try |
| 131 { | 131 { |
| 132 elements = all ? subtree.querySelectorAll(selector) : | 132 elements = all ? subtree.querySelectorAll(selector) : |
| 133 subtree.querySelector(selector); | 133 subtree.querySelector(selector); |
| 134 scopeSupported = true; | 134 scopeSupported = true; |
| 135 } | 135 } |
| 136 catch (e) | 136 catch (e) |
| 137 { | 137 { |
| 138 // Edge doesn't support ":scope" | |
| 138 scopeSupported = false; | 139 scopeSupported = false; |
|
Manish Jethani
2018/01/30 05:53:41
Maybe we should add that comment here saying that
hub
2018/01/30 16:03:57
Done.
| |
| 139 } | 140 } |
| 140 return elements; | 141 return elements; |
| 141 } | 142 } |
| 142 | 143 |
| 143 /** | 144 /** |
| 144 * Query selector. If it is relative, will try :scoped. | 145 * Query selector. If it is relative, will try :scope. |
|
Manish Jethani
2018/01/30 05:53:41
You meant ":scope" (without the D)?
hub
2018/01/30 16:03:57
Done.
| |
| 145 * @param {Node} subtree the element to query selector | 146 * @param {Node} subtree the element to query selector |
| 146 * @param {string} selector the selector to query | 147 * @param {string} selector the selector to query |
| 147 * @param {bool} all True to perform querySelectorAll() | 148 * @param {bool} [all=false] true to perform querySelectorAll() |
|
Manish Jethani
2018/01/30 05:53:41
Since all is optional and defaults to false, I gue
hub
2018/01/30 16:03:57
Done.
| |
| 148 * @returns {Node|NodeList} result of the query. null in case of error. | 149 * @returns {?(Node|NodeList)} result of the query. null in case of error. |
|
Manish Jethani
2018/01/30 05:53:41
Since this can return null I think it should be "{
lainverse
2018/01/30 15:28:29
BTW, wouldn't it be better to return empty array w
hub
2018/01/30 16:03:57
Done.
| |
| 149 */ | 150 */ |
| 150 function scopedQuerySelector(subtree, selector, all) | 151 function scopedQuerySelector(subtree, selector, all) |
| 151 { | 152 { |
| 152 if (relativeSelectorRegexp.test(selector)) | 153 if (selector[0] == ">") |
| 153 { | 154 { |
| 154 selector = ":scope" + selector; | 155 selector = ":scope" + selector; |
| 155 if (scopeSupported) | 156 if (scopeSupported) |
| 156 { | 157 { |
| 157 return all ? subtree.querySelectorAll(selector) : | 158 return all ? subtree.querySelectorAll(selector) : |
| 158 subtree.querySelector(selector); | 159 subtree.querySelector(selector); |
| 159 } | 160 } |
| 160 if (scopeSupported == null) | 161 if (scopeSupported == null) |
| 161 return tryQuerySelector(subtree, selector, all); | 162 return tryQuerySelector(subtree, selector, all); |
| 162 return null; | 163 return null; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 * @param {string} prefix the prefix for the selector. | 204 * @param {string} prefix the prefix for the selector. |
| 204 * @param {Node} subtree the subtree we work on. | 205 * @param {Node} subtree the subtree we work on. |
| 205 * @param {StringifiedStyle[]} styles the stringified style objects. | 206 * @param {StringifiedStyle[]} styles the stringified style objects. |
| 206 */ | 207 */ |
| 207 *getSelectors(prefix, subtree, styles) | 208 *getSelectors(prefix, subtree, styles) |
| 208 { | 209 { |
| 209 yield [prefix + this._selector, subtree]; | 210 yield [prefix + this._selector, subtree]; |
| 210 } | 211 } |
| 211 }; | 212 }; |
| 212 | 213 |
| 213 const incompletePrefixRegexp = /[\s>+~]$/; | 214 const incompletePrefixRegexp = /[\s>+~]$/; |
|
lainverse
2018/01/30 18:07:28
Since that other regexp were replaced with string
Manish Jethani
2018/01/30 20:23:20
If we do this then I think that it should be a sep
| |
| 214 const relativeSelectorRegexp = /^>/; | |
|
Manish Jethani
2018/01/30 06:13:06
So I ran this on Chrome and Firefox:
{
let u =
hub
2018/01/30 16:03:57
Done.
| |
| 215 | 215 |
| 216 function HasSelector(selectors) | 216 function HasSelector(selectors) |
| 217 { | 217 { |
| 218 this._innerSelectors = selectors; | 218 this._innerSelectors = selectors; |
| 219 } | 219 } |
| 220 | 220 |
| 221 HasSelector.prototype = { | 221 HasSelector.prototype = { |
| 222 requiresHiding: true, | 222 requiresHiding: true, |
| 223 | 223 |
| 224 get dependsOnStyles() | 224 get dependsOnStyles() |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 characterData: true, | 646 characterData: true, |
| 647 subtree: true | 647 subtree: true |
| 648 } | 648 } |
| 649 ); | 649 ); |
| 650 this.document.addEventListener("load", this.onLoad.bind(this), true); | 650 this.document.addEventListener("load", this.onLoad.bind(this), true); |
| 651 } | 651 } |
| 652 } | 652 } |
| 653 }; | 653 }; |
| 654 | 654 |
| 655 exports.ElemHideEmulation = ElemHideEmulation; | 655 exports.ElemHideEmulation = ElemHideEmulation; |
| LEFT | RIGHT |