Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/content/elemHideEmulation.js

Issue 29517687: Issue 5079, 5516 - Use webpack for browser tests, modules for content scripts (Closed)
Patch Set: Addressed nits Created Aug. 17, 2017, 1:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/common.js ('k') | package.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 /* globals filterToRegExp */ 18 "use strict";
19 19
20 "use strict"; 20 const {filterToRegExp, splitSelector} = require("common");
21 21
22 const MIN_INVOCATION_INTERVAL = 3000; 22 const MIN_INVOCATION_INTERVAL = 3000;
23 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; 23 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i;
24 24
25 function splitSelector(selector)
26 {
27 if (selector.indexOf(",") == -1)
28 return [selector];
29
30 let selectors = [];
31 let start = 0;
32 let level = 0;
33 let sep = "";
34
35 for (let i = 0; i < selector.length; i++)
36 {
37 let chr = selector[i];
38
39 if (chr == "\\") // ignore escaped characters
40 i++;
41 else if (chr == sep) // don't split within quoted text
42 sep = ""; // e.g. [attr=","]
43 else if (sep == "")
44 {
45 if (chr == '"' || chr == "'")
46 sep = chr;
47 else if (chr == "(") // don't split between parentheses
48 level++; // e.g. :matches(div,span)
49 else if (chr == ")")
50 level = Math.max(0, level - 1);
51 else if (chr == "," && level == 0)
52 {
53 selectors.push(selector.substring(start, i));
54 start = i + 1;
55 }
56 }
57 }
58
59 selectors.push(selector.substring(start));
60 return selectors;
61 }
62
63 /** Return position of node from parent. 25 /** Return position of node from parent.
64 * @param {Node} node the node to find the position of. 26 * @param {Node} node the node to find the position of.
65 * @return {number} One-based index like for :nth-child(), or 0 on error. 27 * @return {number} One-based index like for :nth-child(), or 0 on error.
66 */ 28 */
67 function positionInParent(node) 29 function positionInParent(node)
68 { 30 {
69 let {children} = node.parentNode; 31 let {children} = node.parentNode;
70 for (let i = 0; i < children.length; i++) 32 for (let i = 0; i < children.length; i++)
71 if (children[i] == node) 33 if (children[i] == node)
72 return i + 1; 34 return i + 1;
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 467
506 if (this.patterns.length > 0) 468 if (this.patterns.length > 0)
507 { 469 {
508 let {document} = this.window; 470 let {document} = this.window;
509 this.addSelectors(); 471 this.addSelectors();
510 document.addEventListener("load", this.onLoad.bind(this), true); 472 document.addEventListener("load", this.onLoad.bind(this), true);
511 } 473 }
512 }); 474 });
513 } 475 }
514 }; 476 };
477
478 exports.ElemHideEmulation = ElemHideEmulation;
OLDNEW
« no previous file with comments | « lib/common.js ('k') | package.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld