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 /** | 20 /** |
21 * @fileOverview Element hiding implementation. | 21 * @fileOverview Element hiding implementation. |
22 */ | 22 */ |
23 | 23 |
24 const {ElemHideExceptions} = require("./elemHideExceptions"); | 24 const {ElemHideExceptions} = require("./elemHideExceptions"); |
25 const {FilterNotifier} = require("./filterNotifier"); | 25 const {filterNotifier} = require("./filterNotifier"); |
26 | 26 |
27 /** | 27 /** |
28 * Lookup table, active flag, by filter by domain. | 28 * Lookup table, active flag, by filter by domain. |
29 * (Only contains filters that aren't unconditionally matched for all domains.) | 29 * (Only contains filters that aren't unconditionally matched for all domains.) |
30 * @type {Map.<string,Map.<Filter,boolean>>} | 30 * @type {Map.<string,Map.<Filter,boolean>>} |
31 */ | 31 */ |
32 let filtersByDomain = new Map(); | 32 let filtersByDomain = new Map(); |
33 | 33 |
34 /** | 34 /** |
35 * Lookup table, filter by selector. (Only used for selectors that are | 35 * Lookup table, filter by selector. (Only used for selectors that are |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 exports.ElemHide = { | 111 exports.ElemHide = { |
112 /** | 112 /** |
113 * Removes all known filters | 113 * Removes all known filters |
114 */ | 114 */ |
115 clear() | 115 clear() |
116 { | 116 { |
117 for (let collection of [filtersByDomain, filterBySelector, knownFilters]) | 117 for (let collection of [filtersByDomain, filterBySelector, knownFilters]) |
118 collection.clear(); | 118 collection.clear(); |
119 | 119 |
120 unconditionalSelectors = null; | 120 unconditionalSelectors = null; |
121 FilterNotifier.emit("elemhideupdate"); | 121 filterNotifier.emit("elemhideupdate"); |
122 }, | 122 }, |
123 | 123 |
124 /** | 124 /** |
125 * Add a new element hiding filter | 125 * Add a new element hiding filter |
126 * @param {ElemHideFilter} filter | 126 * @param {ElemHideFilter} filter |
127 */ | 127 */ |
128 add(filter) | 128 add(filter) |
129 { | 129 { |
130 if (knownFilters.has(filter)) | 130 if (knownFilters.has(filter)) |
131 return; | 131 return; |
132 | 132 |
133 let {selector} = filter; | 133 let {selector} = filter; |
134 | 134 |
135 if (!(filter.domains || ElemHideExceptions.hasExceptions(selector))) | 135 if (!(filter.domains || ElemHideExceptions.hasExceptions(selector))) |
136 { | 136 { |
137 // The new filter's selector is unconditionally applied to all domains | 137 // The new filter's selector is unconditionally applied to all domains |
138 filterBySelector.set(selector, filter); | 138 filterBySelector.set(selector, filter); |
139 unconditionalSelectors = null; | 139 unconditionalSelectors = null; |
140 } | 140 } |
141 else | 141 else |
142 { | 142 { |
143 // The new filter's selector only applies to some domains | 143 // The new filter's selector only applies to some domains |
144 addToFiltersByDomain(filter); | 144 addToFiltersByDomain(filter); |
145 } | 145 } |
146 | 146 |
147 knownFilters.add(filter); | 147 knownFilters.add(filter); |
148 FilterNotifier.emit("elemhideupdate"); | 148 filterNotifier.emit("elemhideupdate"); |
149 }, | 149 }, |
150 | 150 |
151 /** | 151 /** |
152 * Removes an element hiding filter | 152 * Removes an element hiding filter |
153 * @param {ElemHideFilter} filter | 153 * @param {ElemHideFilter} filter |
154 */ | 154 */ |
155 remove(filter) | 155 remove(filter) |
156 { | 156 { |
157 if (!knownFilters.has(filter)) | 157 if (!knownFilters.has(filter)) |
158 return; | 158 return; |
(...skipping 17 matching lines...) Expand all Loading... |
176 { | 176 { |
177 filters.delete(filter); | 177 filters.delete(filter); |
178 | 178 |
179 if (filters.size == 0) | 179 if (filters.size == 0) |
180 filtersByDomain.delete(domain); | 180 filtersByDomain.delete(domain); |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 knownFilters.delete(filter); | 185 knownFilters.delete(filter); |
186 FilterNotifier.emit("elemhideupdate"); | 186 filterNotifier.emit("elemhideupdate"); |
187 }, | 187 }, |
188 | 188 |
189 /** | 189 /** |
190 * Determines from the current filter list which selectors should be applied | 190 * Determines from the current filter list which selectors should be applied |
191 * on a particular host name. | 191 * on a particular host name. |
192 * @param {string} domain | 192 * @param {string} domain |
193 * @param {boolean} [specificOnly] true if generic filters should not apply. | 193 * @param {boolean} [specificOnly] true if generic filters should not apply. |
194 * @returns {string[]} List of selectors. | 194 * @returns {string[]} List of selectors. |
195 */ | 195 */ |
196 getSelectorsForDomain(domain, specificOnly = false) | 196 getSelectorsForDomain(domain, specificOnly = false) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 let nextDot = currentDomain.indexOf("."); | 234 let nextDot = currentDomain.indexOf("."); |
235 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 235 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
236 } | 236 } |
237 | 237 |
238 if (!specificOnly) | 238 if (!specificOnly) |
239 selectors = getUnconditionalSelectors().concat(selectors); | 239 selectors = getUnconditionalSelectors().concat(selectors); |
240 | 240 |
241 return selectors; | 241 return selectors; |
242 } | 242 } |
243 }; | 243 }; |
OLD | NEW |