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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const {textToRegExp, filterToRegExp, splitSelector} = require("../common"); | 20 const {textToRegExp, filterToRegExp, splitSelector} = require("../common"); |
| 21 const {findIndex} = require("../coreUtils"); |
21 | 22 |
22 let MIN_INVOCATION_INTERVAL = 3000; | 23 let MIN_INVOCATION_INTERVAL = 3000; |
23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; | 24 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; |
24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; | 25 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; |
25 | 26 |
26 /** Return position of node from parent. | 27 /** Return position of node from parent. |
27 * @param {Node} node the node to find the position of. | 28 * @param {Node} node the node to find the position of. |
28 * @return {number} One-based index like for :nth-child(), or 0 on error. | 29 * @return {number} One-based index like for :nth-child(), or 0 on error. |
29 */ | 30 */ |
30 function positionInParent(node) | 31 function positionInParent(node) |
31 { | 32 { |
32 let {children} = node.parentNode; | 33 return findIndex(node.parentNode.children, child => child == node) + 1; |
33 for (let i = 0; i < children.length; i++) | |
34 if (children[i] == node) | |
35 return i + 1; | |
36 return 0; | |
37 } | 34 } |
38 | 35 |
39 function makeSelector(node, selector) | 36 function makeSelector(node, selector) |
40 { | 37 { |
41 if (node == null) | 38 if (node == null) |
42 return null; | 39 return null; |
43 if (!node.parentElement) | 40 if (!node.parentElement) |
44 { | 41 { |
45 let newSelector = ":root"; | 42 let newSelector = ":root"; |
46 if (selector) | 43 if (selector) |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 characterData: shouldObserveCharacterData(this.patterns), | 709 characterData: shouldObserveCharacterData(this.patterns), |
713 subtree: true | 710 subtree: true |
714 } | 711 } |
715 ); | 712 ); |
716 this.document.addEventListener("load", this.onLoad.bind(this), true); | 713 this.document.addEventListener("load", this.onLoad.bind(this), true); |
717 } | 714 } |
718 } | 715 } |
719 }; | 716 }; |
720 | 717 |
721 exports.ElemHideEmulation = ElemHideEmulation; | 718 exports.ElemHideEmulation = ElemHideEmulation; |
OLD | NEW |