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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 * Add a new element hiding filter | 101 * Add a new element hiding filter |
102 * @param {ElemHideBase} filter | 102 * @param {ElemHideBase} filter |
103 */ | 103 */ |
104 add(filter) | 104 add(filter) |
105 { | 105 { |
106 if (knownFilters.has(filter)) | 106 if (knownFilters.has(filter)) |
107 return; | 107 return; |
108 | 108 |
109 if (filter instanceof ElemHideException) | 109 if (filter instanceof ElemHideException) |
110 { | 110 { |
111 let {selector} = filter; | 111 let {code} = filter; |
112 let list = exceptions.get(selector); | 112 let list = exceptions.get(code); |
113 if (list) | 113 if (list) |
114 list.push(filter); | 114 list.push(filter); |
115 else | 115 else |
116 exceptions.set(selector, [filter]); | 116 exceptions.set(code, [filter]); |
117 | 117 |
118 // If this is the first exception for a previously unconditionally | 118 // If this is the first exception for a previously unconditionally |
119 // applied element hiding selector we need to take care to update the | 119 // applied element hiding selector we need to take care to update the |
120 // lookups. | 120 // lookups. |
121 let unconditionalFilterForSelector = filterBySelector.get(selector); | 121 let unconditionalFilterForSelector = filterBySelector.get(code); |
122 if (unconditionalFilterForSelector) | 122 if (unconditionalFilterForSelector) |
123 { | 123 { |
124 this._addToFiltersByDomain(unconditionalFilterForSelector); | 124 this._addToFiltersByDomain(unconditionalFilterForSelector); |
125 filterBySelector.delete(selector); | 125 filterBySelector.delete(code); |
126 unconditionalSelectors = null; | 126 unconditionalSelectors = null; |
127 } | 127 } |
128 } | 128 } |
129 else if (!(filter.domains || exceptions.has(filter.selector))) | 129 else if (!(filter.domains || exceptions.has(filter.code))) |
130 { | 130 { |
131 // The new filter's selector is unconditionally applied to all domains | 131 // The new filter's selector is unconditionally applied to all domains |
132 filterBySelector.set(filter.selector, filter); | 132 filterBySelector.set(filter.code, filter); |
133 unconditionalSelectors = null; | 133 unconditionalSelectors = null; |
134 } | 134 } |
135 else | 135 else |
136 { | 136 { |
137 // The new filter's selector only applies to some domains | 137 // The new filter's selector only applies to some domains |
138 this._addToFiltersByDomain(filter); | 138 this._addToFiltersByDomain(filter); |
139 } | 139 } |
140 | 140 |
141 knownFilters.add(filter); | 141 knownFilters.add(filter); |
142 FilterNotifier.emit("elemhideupdate"); | 142 FilterNotifier.emit("elemhideupdate"); |
143 }, | 143 }, |
144 | 144 |
145 /** | 145 /** |
146 * Removes an element hiding filter | 146 * Removes an element hiding filter |
147 * @param {ElemHideBase} filter | 147 * @param {ElemHideBase} filter |
148 */ | 148 */ |
149 remove(filter) | 149 remove(filter) |
150 { | 150 { |
151 if (!knownFilters.has(filter)) | 151 if (!knownFilters.has(filter)) |
152 return; | 152 return; |
153 | 153 |
154 // Whitelisting filters | 154 // Whitelisting filters |
155 if (filter instanceof ElemHideException) | 155 if (filter instanceof ElemHideException) |
156 { | 156 { |
157 let list = exceptions.get(filter.selector); | 157 let list = exceptions.get(filter.code); |
158 let index = list.indexOf(filter); | 158 let index = list.indexOf(filter); |
159 if (index >= 0) | 159 if (index >= 0) |
160 list.splice(index, 1); | 160 list.splice(index, 1); |
161 } | 161 } |
162 // Unconditially applied element hiding filters | 162 // Unconditially applied element hiding filters |
163 else if (filterBySelector.get(filter.selector) == filter) | 163 else if (filterBySelector.get(filter.code) == filter) |
164 { | 164 { |
165 filterBySelector.delete(filter.selector); | 165 filterBySelector.delete(filter.code); |
166 unconditionalSelectors = null; | 166 unconditionalSelectors = null; |
167 } | 167 } |
168 // Conditionally applied element hiding filters | 168 // Conditionally applied element hiding filters |
169 else | 169 else |
170 { | 170 { |
171 let domains = filter.domains || defaultDomains; | 171 let domains = filter.domains || defaultDomains; |
172 for (let domain of domains.keys()) | 172 for (let domain of domains.keys()) |
173 { | 173 { |
174 let filters = filtersByDomain.get(domain); | 174 let filters = filtersByDomain.get(domain); |
175 if (filters) | 175 if (filters) |
176 filters.delete(filter); | 176 filters.delete(filter); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 knownFilters.delete(filter); | 180 knownFilters.delete(filter); |
181 FilterNotifier.emit("elemhideupdate"); | 181 FilterNotifier.emit("elemhideupdate"); |
182 }, | 182 }, |
183 | 183 |
184 /** | 184 /** |
185 * Checks whether an exception rule is registered for a filter on a particular | 185 * Checks whether an exception rule is registered for a filter on a particular |
186 * domain. | 186 * domain. |
187 * @param {Filter} filter | 187 * @param {Filter} filter |
188 * @param {string} docDomain | 188 * @param {string} docDomain |
189 * @return {ElemHideException} | 189 * @return {ElemHideException} |
190 */ | 190 */ |
191 getException(filter, docDomain) | 191 getException(filter, docDomain) |
192 { | 192 { |
193 let list = exceptions.get(filter.selector); | 193 let list = exceptions.get(filter.code); |
194 if (!list) | 194 if (!list) |
195 return null; | 195 return null; |
196 | 196 |
197 for (let i = list.length - 1; i >= 0; i--) | 197 for (let i = list.length - 1; i >= 0; i--) |
198 { | 198 { |
199 if (list[i].isActiveOnDomain(docDomain)) | 199 if (list[i].isActiveOnDomain(docDomain)) |
200 return list[i]; | 200 return list[i]; |
201 } | 201 } |
202 | 202 |
203 return null; | 203 return null; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 { | 267 { |
268 for (let [filter, isIncluded] of filters) | 268 for (let [filter, isIncluded] of filters) |
269 { | 269 { |
270 if (!isIncluded) | 270 if (!isIncluded) |
271 { | 271 { |
272 excluded.add(filter); | 272 excluded.add(filter); |
273 } | 273 } |
274 else if ((excluded.size == 0 || !excluded.has(filter)) && | 274 else if ((excluded.size == 0 || !excluded.has(filter)) && |
275 !this.getException(filter, domain)) | 275 !this.getException(filter, domain)) |
276 { | 276 { |
277 selectors.push(filter.selector); | 277 selectors.push(filter.code); |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 if (currentDomain == "") | 282 if (currentDomain == "") |
283 break; | 283 break; |
284 | 284 |
285 let nextDot = currentDomain.indexOf("."); | 285 let nextDot = currentDomain.indexOf("."); |
286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 286 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
287 } | 287 } |
288 | 288 |
289 return selectors; | 289 return selectors; |
290 } | 290 } |
291 }; | 291 }; |
OLD | NEW |