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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 const {ElemHideException} = require("filterClasses"); | 24 const {ElemHideException} = require("filterClasses"); |
25 const {FilterNotifier} = require("filterNotifier"); | 25 const {FilterNotifier} = require("filterNotifier"); |
26 | 26 |
27 /** | 27 /** |
28 * Lookup table, filters by their associated key | 28 * Lookup table, filters by their associated key |
29 * @type {Object} | 29 * @type {Object} |
30 */ | 30 */ |
31 let filterByKey = []; | 31 let filterByKey = []; |
32 | 32 |
33 /** | 33 /** |
34 * Lookup table, keys of the filters by filter text | 34 * Lookup table, keys of the filters by filter |
35 * @type {Object} | 35 * @type {Map.<Filter,string>} |
36 */ | 36 */ |
37 let keyByFilter = Object.create(null); | 37 let keyByFilter = new Map(); |
38 | 38 |
39 /** | 39 /** |
40 * Nested lookup table, filter (or false if inactive) by filter key by domain. | 40 * Nested lookup table, filter (or false if inactive) by filter key by domain. |
41 * (Only contains filters that aren't unconditionally matched for all domains.) | 41 * (Only contains filters that aren't unconditionally matched for all domains.) |
42 * @type {Map.<string,Map.<string,(Filter|boolean)>>} | 42 * @type {Map.<string,Map.<string,(Filter|boolean)>>} |
43 */ | 43 */ |
44 let filtersByDomain = new Map(); | 44 let filtersByDomain = new Map(); |
45 | 45 |
46 /** | 46 /** |
47 * Lookup table, filter key by selector. (Only used for selectors that are | 47 * Lookup table, filter key by selector. (Only used for selectors that are |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 * Container for element hiding filters | 84 * Container for element hiding filters |
85 * @class | 85 * @class |
86 */ | 86 */ |
87 let ElemHide = exports.ElemHide = { | 87 let ElemHide = exports.ElemHide = { |
88 /** | 88 /** |
89 * Removes all known filters | 89 * Removes all known filters |
90 */ | 90 */ |
91 clear() | 91 clear() |
92 { | 92 { |
93 filterByKey = []; | 93 filterByKey = []; |
94 keyByFilter = Object.create(null); | 94 keyByFilter = new Map(); |
95 filtersByDomain = new Map(); | 95 filtersByDomain = new Map(); |
96 filterKeyBySelector = Object.create(null); | 96 filterKeyBySelector = Object.create(null); |
97 unconditionalSelectors = unconditionalFilterKeys = null; | 97 unconditionalSelectors = unconditionalFilterKeys = null; |
98 knownExceptions = Object.create(null); | 98 knownExceptions = Object.create(null); |
99 exceptions = Object.create(null); | 99 exceptions = Object.create(null); |
100 FilterNotifier.emit("elemhideupdate"); | 100 FilterNotifier.emit("elemhideupdate"); |
101 }, | 101 }, |
102 | 102 |
103 _addToFiltersByDomain(key, filter) | 103 _addToFiltersByDomain(key, filter) |
104 { | 104 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 { | 136 { |
137 this._addToFiltersByDomain(filterKey, filterByKey[filterKey]); | 137 this._addToFiltersByDomain(filterKey, filterByKey[filterKey]); |
138 delete filterKeyBySelector[selector]; | 138 delete filterKeyBySelector[selector]; |
139 unconditionalSelectors = unconditionalFilterKeys = null; | 139 unconditionalSelectors = unconditionalFilterKeys = null; |
140 } | 140 } |
141 | 141 |
142 knownExceptions[filter.text] = true; | 142 knownExceptions[filter.text] = true; |
143 } | 143 } |
144 else | 144 else |
145 { | 145 { |
146 if (filter.text in keyByFilter) | 146 if (keyByFilter.has(filter)) |
147 return; | 147 return; |
148 | 148 |
149 let key = filterByKey.push(filter) - 1; | 149 let key = filterByKey.push(filter) - 1; |
150 keyByFilter[filter.text] = key; | 150 keyByFilter.set(filter, key); |
151 | 151 |
152 if (!(filter.domains || filter.selector in exceptions)) | 152 if (!(filter.domains || filter.selector in exceptions)) |
153 { | 153 { |
154 // The new filter's selector is unconditionally applied to all domains | 154 // The new filter's selector is unconditionally applied to all domains |
155 filterKeyBySelector[filter.selector] = key; | 155 filterKeyBySelector[filter.selector] = key; |
156 unconditionalSelectors = unconditionalFilterKeys = null; | 156 unconditionalSelectors = unconditionalFilterKeys = null; |
157 } | 157 } |
158 else | 158 else |
159 { | 159 { |
160 // The new filter's selector only applies to some domains | 160 // The new filter's selector only applies to some domains |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return; | 197 return; |
198 | 198 |
199 let list = exceptions[filter.selector]; | 199 let list = exceptions[filter.selector]; |
200 let index = list.indexOf(filter); | 200 let index = list.indexOf(filter); |
201 if (index >= 0) | 201 if (index >= 0) |
202 list.splice(index, 1); | 202 list.splice(index, 1); |
203 delete knownExceptions[filter.text]; | 203 delete knownExceptions[filter.text]; |
204 } | 204 } |
205 else | 205 else |
206 { | 206 { |
207 if (!(filter.text in keyByFilter)) | 207 let key = keyByFilter.get(filter); |
| 208 if (typeof key == "undefined") |
208 return; | 209 return; |
209 | 210 |
210 let key = keyByFilter[filter.text]; | |
211 delete filterByKey[key]; | 211 delete filterByKey[key]; |
212 delete keyByFilter[filter.text]; | 212 keyByFilter.delete(filter); |
213 this._removeFilterKey(key, filter); | 213 this._removeFilterKey(key, filter); |
214 } | 214 } |
215 | 215 |
216 FilterNotifier.emit("elemhideupdate"); | 216 FilterNotifier.emit("elemhideupdate"); |
217 }, | 217 }, |
218 | 218 |
219 /** | 219 /** |
220 * Checks whether an exception rule is registered for a filter on a particular | 220 * Checks whether an exception rule is registered for a filter on a particular |
221 * domain. | 221 * domain. |
222 * @param {Filter} filter | 222 * @param {Filter} filter |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 381 |
382 let nextDot = currentDomain.indexOf("."); | 382 let nextDot = currentDomain.indexOf("."); |
383 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 383 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
384 } | 384 } |
385 | 385 |
386 if (provideFilterKeys) | 386 if (provideFilterKeys) |
387 return [selectors, filterKeys]; | 387 return [selectors, filterKeys]; |
388 return selectors; | 388 return selectors; |
389 } | 389 } |
390 }; | 390 }; |
OLD | NEW |