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 {indexOf} = 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 function getCachedPropertyValue(object, name, defaultValueFunc = () => {}) | 27 function getCachedPropertyValue(object, name, defaultValueFunc = () => {}) |
27 { | 28 { |
28 let value = object[name]; | 29 let value = object[name]; |
29 if (typeof value == "undefined") | 30 if (typeof value == "undefined") |
30 Object.defineProperty(object, name, {value: value = defaultValueFunc()}); | 31 Object.defineProperty(object, name, {value: value = defaultValueFunc()}); |
31 return value; | 32 return value; |
32 } | 33 } |
33 | 34 |
34 /** Return position of node from parent. | 35 /** Return position of node from parent. |
35 * @param {Node} node the node to find the position of. | 36 * @param {Node} node the node to find the position of. |
36 * @return {number} One-based index like for :nth-child(), or 0 on error. | 37 * @return {number} One-based index like for :nth-child(), or 0 on error. |
37 */ | 38 */ |
38 function positionInParent(node) | 39 function positionInParent(node) |
39 { | 40 { |
40 let {children} = node.parentNode; | 41 return indexOf(node.parentNode.children, node) + 1; |
41 for (let i = 0; i < children.length; i++) | |
42 if (children[i] == node) | |
43 return i + 1; | |
44 return 0; | |
45 } | 42 } |
46 | 43 |
47 function makeSelector(node, selector) | 44 function makeSelector(node, selector) |
48 { | 45 { |
49 if (node == null) | 46 if (node == null) |
50 return null; | 47 return null; |
51 if (!node.parentElement) | 48 if (!node.parentElement) |
52 { | 49 { |
53 let newSelector = ":root"; | 50 let newSelector = ":root"; |
54 if (selector) | 51 if (selector) |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 characterData: shouldObserveCharacterData(this.patterns), | 806 characterData: shouldObserveCharacterData(this.patterns), |
810 subtree: true | 807 subtree: true |
811 } | 808 } |
812 ); | 809 ); |
813 this.document.addEventListener("load", this.onLoad.bind(this), true); | 810 this.document.addEventListener("load", this.onLoad.bind(this), true); |
814 } | 811 } |
815 } | 812 } |
816 }; | 813 }; |
817 | 814 |
818 exports.ElemHideEmulation = ElemHideEmulation; | 815 exports.ElemHideEmulation = ElemHideEmulation; |
OLD | NEW |