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

Side by Side Diff: lib/elemHideExceptions.js

Issue 29868577: Issue 6891 - Rename FilterNotifier to filterNotifier (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 29, 2018, 2 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/elemHide.js ('k') | lib/filterClasses.js » ('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-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 /** 20 /**
21 * @fileOverview Element hiding exceptions implementation. 21 * @fileOverview Element hiding exceptions implementation.
22 */ 22 */
23 23
24 const {EventEmitter} = require("./events"); 24 const {EventEmitter} = require("./events");
25 const {FilterNotifier} = require("./filterNotifier"); 25 const {filterNotifier} = require("./filterNotifier");
26 26
27 /** 27 /**
28 * Lookup table, lists of element hiding exceptions by selector 28 * Lookup table, lists of element hiding exceptions by selector
29 * @type {Map.<string,ElemHideException[]>} 29 * @type {Map.<string,ElemHideException[]>}
30 */ 30 */
31 let exceptions = new Map(); 31 let exceptions = new Map();
32 32
33 /** 33 /**
34 * Set containing known element exceptions 34 * Set containing known element exceptions
35 * @type {Set.<ElemHideException>} 35 * @type {Set.<ElemHideException>}
36 */ 36 */
37 let knownExceptions = new Set(); 37 let knownExceptions = new Set();
38 38
39 /** 39 /**
40 * Container for element hiding exceptions 40 * Container for element hiding exceptions
41 * @class 41 * @class
42 */ 42 */
43 exports.ElemHideExceptions = Object.assign(Object.create(new EventEmitter()), { 43 exports.ElemHideExceptions = Object.assign(Object.create(new EventEmitter()), {
44 /** 44 /**
45 * Removes all known exceptions 45 * Removes all known exceptions
46 */ 46 */
47 clear() 47 clear()
48 { 48 {
49 exceptions.clear(); 49 exceptions.clear();
50 knownExceptions.clear(); 50 knownExceptions.clear();
51 51
52 FilterNotifier.emit("elemhideupdate"); 52 filterNotifier.emit("elemhideupdate");
53 }, 53 },
54 54
55 /** 55 /**
56 * Add a new element hiding exception 56 * Add a new element hiding exception
57 * @param {ElemHideException} exception 57 * @param {ElemHideException} exception
58 */ 58 */
59 add(exception) 59 add(exception)
60 { 60 {
61 if (knownExceptions.has(exception)) 61 if (knownExceptions.has(exception))
62 return; 62 return;
63 63
64 let {selector} = exception; 64 let {selector} = exception;
65 let list = exceptions.get(selector); 65 let list = exceptions.get(selector);
66 if (list) 66 if (list)
67 list.push(exception); 67 list.push(exception);
68 else 68 else
69 exceptions.set(selector, [exception]); 69 exceptions.set(selector, [exception]);
70 70
71 knownExceptions.add(exception); 71 knownExceptions.add(exception);
72 72
73 this.emit("added", exception); 73 this.emit("added", exception);
74 74
75 FilterNotifier.emit("elemhideupdate"); 75 filterNotifier.emit("elemhideupdate");
76 }, 76 },
77 77
78 /** 78 /**
79 * Removes an element hiding exception 79 * Removes an element hiding exception
80 * @param {ElemHideException} exception 80 * @param {ElemHideException} exception
81 */ 81 */
82 remove(exception) 82 remove(exception)
83 { 83 {
84 if (!knownExceptions.has(exception)) 84 if (!knownExceptions.has(exception))
85 return; 85 return;
86 86
87 let list = exceptions.get(exception.selector); 87 let list = exceptions.get(exception.selector);
88 let index = list.indexOf(exception); 88 let index = list.indexOf(exception);
89 if (index >= 0) 89 if (index >= 0)
90 list.splice(index, 1); 90 list.splice(index, 1);
91 91
92 knownExceptions.delete(exception); 92 knownExceptions.delete(exception);
93 93
94 this.emit("removed", exception); 94 this.emit("removed", exception);
95 95
96 FilterNotifier.emit("elemhideupdate"); 96 filterNotifier.emit("elemhideupdate");
97 }, 97 },
98 98
99 /** 99 /**
100 * Checks whether any exception rules are registered for a selector 100 * Checks whether any exception rules are registered for a selector
101 * @param {string} selector 101 * @param {string} selector
102 * @returns {boolean} 102 * @returns {boolean}
103 */ 103 */
104 hasExceptions(selector) 104 hasExceptions(selector)
105 { 105 {
106 return exceptions.has(selector); 106 return exceptions.has(selector);
(...skipping 14 matching lines...) Expand all
121 121
122 for (let i = list.length - 1; i >= 0; i--) 122 for (let i = list.length - 1; i >= 0; i--)
123 { 123 {
124 if (list[i].isActiveOnDomain(docDomain)) 124 if (list[i].isActiveOnDomain(docDomain))
125 return list[i]; 125 return list[i];
126 } 126 }
127 127
128 return null; 128 return null;
129 } 129 }
130 }); 130 });
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld