LEFT | RIGHT |
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 /** | 133 /** |
134 * Notifies Matcher instances or ElemHide object about a new filter | 134 * Notifies Matcher instances or ElemHide object about a new filter |
135 * if necessary. | 135 * if necessary. |
136 * @param {Filter} filter filter that has been added | 136 * @param {Filter} filter filter that has been added |
137 */ | 137 */ |
138 function addFilter(filter) | 138 function addFilter(filter) |
139 { | 139 { |
140 if (!(filter instanceof ActiveFilter) || filter.disabled) | 140 if (!(filter instanceof ActiveFilter) || filter.disabled) |
141 return; | 141 return; |
142 | 142 |
143 if (!filter.subscriptionsAdded) | |
144 filterStorage.addSubscriptionsToFilter(filter); | |
145 | |
146 let hasEnabled = false; | 143 let hasEnabled = false; |
147 let allowSnippets = false; | 144 let allowSnippets = false; |
148 for (let subscription of filter.subscriptions()) | 145 for (let subscription of filterStorage.subscriptionsForFilter(filter)) |
149 { | 146 { |
150 if (!subscription.disabled) | 147 if (!subscription.disabled) |
151 { | 148 { |
152 hasEnabled = true; | 149 hasEnabled = true; |
153 | 150 |
154 // Allow snippets to be executed only by the circumvention lists or the | 151 // Allow snippets to be executed only by the circumvention lists or the |
155 // user's own filters. | 152 // user's own filters. |
156 if (subscription.type == "circumvention" || | 153 if (subscription.type == "circumvention" || |
157 subscription.url == "https://easylist-downloads.adblockplus.org/abp-fi
lters-anti-cv.txt" || | 154 subscription.url == "https://easylist-downloads.adblockplus.org/abp-fi
lters-anti-cv.txt" || |
158 subscription instanceof SpecialSubscription) | 155 subscription instanceof SpecialSubscription) |
(...skipping 26 matching lines...) Expand all Loading... |
185 * if necessary. | 182 * if necessary. |
186 * @param {Filter} filter filter that has been removed | 183 * @param {Filter} filter filter that has been removed |
187 */ | 184 */ |
188 function removeFilter(filter) | 185 function removeFilter(filter) |
189 { | 186 { |
190 if (!(filter instanceof ActiveFilter)) | 187 if (!(filter instanceof ActiveFilter)) |
191 return; | 188 return; |
192 | 189 |
193 if (!filter.disabled) | 190 if (!filter.disabled) |
194 { | 191 { |
195 if (!filter.subscriptionsAdded) | |
196 filterStorage.addSubscriptionsToFilter(filter); | |
197 | |
198 let hasEnabled = false; | 192 let hasEnabled = false; |
199 for (let subscription of filter.subscriptions()) | 193 for (let subscription of filterStorage.subscriptionsForFilter(filter)) |
200 { | 194 { |
201 if (!subscription.disabled) | 195 if (!subscription.disabled) |
202 { | 196 { |
203 hasEnabled = true; | 197 hasEnabled = true; |
204 break; | 198 break; |
205 } | 199 } |
206 } | 200 } |
207 if (hasEnabled) | 201 if (hasEnabled) |
208 return; | 202 return; |
209 } | 203 } |
210 | 204 |
211 if (filter instanceof RegExpFilter) | 205 if (filter instanceof RegExpFilter) |
212 defaultMatcher.remove(filter); | 206 defaultMatcher.remove(filter); |
213 else if (filter instanceof ElemHideBase) | 207 else if (filter instanceof ElemHideBase) |
214 { | 208 { |
215 if (filter instanceof ElemHideFilter) | 209 if (filter instanceof ElemHideFilter) |
216 ElemHide.remove(filter); | 210 ElemHide.remove(filter); |
217 else if (filter instanceof ElemHideEmulationFilter) | 211 else if (filter instanceof ElemHideEmulationFilter) |
218 ElemHideEmulation.remove(filter); | 212 ElemHideEmulation.remove(filter); |
219 else | 213 else |
220 ElemHideExceptions.remove(filter); | 214 ElemHideExceptions.remove(filter); |
221 } | 215 } |
222 else if (filter instanceof SnippetFilter) | 216 else if (filter instanceof SnippetFilter) |
223 Snippets.remove(filter); | 217 Snippets.remove(filter); |
224 } | 218 } |
225 | 219 |
226 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; | 220 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; |
227 | 221 |
228 function addFilters(filters) | 222 function addSubscriptionFilters(subscription) |
229 { | 223 { |
230 // We add filters using pseudo-random ordering. Reason is that ElemHide will | 224 // We add filters using pseudo-random ordering. Reason is that ElemHide will |
231 // assign consecutive filter IDs that might be visible to the website. The | 225 // assign consecutive filter IDs that might be visible to the website. The |
232 // randomization makes sure that no conclusion can be made about the actual | 226 // randomization makes sure that no conclusion can be made about the actual |
233 // filters applying there. We have ten prime numbers to use as iteration step, | 227 // filters applying there. We have ten prime numbers to use as iteration step, |
234 // any of those can be chosen as long as the array length isn't divisible by | 228 // any of those can be chosen as long as the array length isn't divisible by |
235 // it. | 229 // it. |
236 let len = filters.length; | 230 let len = subscription.filterCount; |
237 if (!len) | 231 if (!len) |
238 return; | 232 return; |
239 | 233 |
240 let current = (Math.random() * len) | 0; | 234 let current = (Math.random() * len) | 0; |
241 let step; | 235 let step; |
242 do | 236 do |
243 { | 237 { |
244 step = primes[(Math.random() * primes.length) | 0]; | 238 step = primes[(Math.random() * primes.length) | 0]; |
245 } while (len % step == 0); | 239 } while (len % step == 0); |
246 | 240 |
247 for (let i = 0; i < len; i++, current = (current + step) % len) | 241 for (let i = 0; i < len; i++, current = (current + step) % len) |
248 addFilter(filters[current]); | 242 addFilter(subscription.filterAt(current)); |
249 } | 243 } |
250 | 244 |
251 function onSubscriptionAdded(subscription) | 245 function onSubscriptionAdded(subscription) |
252 { | 246 { |
253 FilterListener.setDirty(1); | 247 FilterListener.setDirty(1); |
254 | 248 |
255 if (!subscription.disabled) | 249 if (!subscription.disabled) |
256 addFilters(subscription.filters); | 250 addSubscriptionFilters(subscription); |
257 } | 251 } |
258 | 252 |
259 function onSubscriptionRemoved(subscription) | 253 function onSubscriptionRemoved(subscription) |
260 { | 254 { |
261 FilterListener.setDirty(1); | 255 FilterListener.setDirty(1); |
262 | 256 |
263 if (!subscription.disabled) | 257 if (!subscription.disabled) |
264 subscription.filters.forEach(removeFilter); | 258 { |
| 259 for (let filter of subscription.filters()) |
| 260 removeFilter(filter); |
| 261 } |
265 } | 262 } |
266 | 263 |
267 function onSubscriptionDisabled(subscription, newValue) | 264 function onSubscriptionDisabled(subscription, newValue) |
268 { | 265 { |
269 FilterListener.setDirty(1); | 266 FilterListener.setDirty(1); |
270 | 267 |
271 if (filterStorage.knownSubscriptions.has(subscription.url)) | 268 if (filterStorage.knownSubscriptions.has(subscription.url)) |
272 { | 269 { |
273 if (newValue == false) | 270 if (newValue == false) |
274 addFilters(subscription.filters); | 271 { |
| 272 addSubscriptionFilters(subscription); |
| 273 } |
275 else | 274 else |
276 subscription.filters.forEach(removeFilter); | 275 { |
| 276 for (let filter of subscription.filters()) |
| 277 removeFilter(filter); |
| 278 } |
277 } | 279 } |
278 } | 280 } |
279 | 281 |
280 function onSubscriptionUpdated(subscription, oldFilters) | 282 function onSubscriptionUpdated(subscription, oldFilters) |
281 { | 283 { |
282 FilterListener.setDirty(1); | 284 FilterListener.setDirty(1); |
283 | 285 |
284 if (!subscription.disabled && | 286 if (!subscription.disabled && |
285 filterStorage.knownSubscriptions.has(subscription.url)) | 287 filterStorage.knownSubscriptions.has(subscription.url)) |
286 { | 288 { |
287 oldFilters.forEach(removeFilter); | 289 for (let filter of oldFilters) |
288 addFilters(subscription.filters); | 290 removeFilter(filter); |
| 291 |
| 292 addSubscriptionFilters(subscription); |
289 } | 293 } |
290 } | 294 } |
291 | 295 |
292 function onFilterHitCount(filter, newValue) | 296 function onFilterHitCount(filter, newValue) |
293 { | 297 { |
294 if (newValue == 0) | 298 if (newValue == 0) |
295 FilterListener.setDirty(0); | 299 FilterListener.setDirty(0); |
296 else | 300 else |
297 FilterListener.setDirty(0.002); | 301 FilterListener.setDirty(0.002); |
298 } | 302 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 339 |
336 function onLoad() | 340 function onLoad() |
337 { | 341 { |
338 isDirty = 0; | 342 isDirty = 0; |
339 | 343 |
340 defaultMatcher.clear(); | 344 defaultMatcher.clear(); |
341 ElemHide.clear(); | 345 ElemHide.clear(); |
342 ElemHideEmulation.clear(); | 346 ElemHideEmulation.clear(); |
343 ElemHideExceptions.clear(); | 347 ElemHideExceptions.clear(); |
344 Snippets.clear(); | 348 Snippets.clear(); |
| 349 |
345 for (let subscription of filterStorage.subscriptions()) | 350 for (let subscription of filterStorage.subscriptions()) |
346 { | 351 { |
347 if (!subscription.disabled) | 352 if (!subscription.disabled) |
348 addFilters(subscription.filters); | 353 addSubscriptionFilters(subscription); |
349 } | 354 } |
350 } | 355 } |
351 | 356 |
352 function onSave() | 357 function onSave() |
353 { | 358 { |
354 isDirty = 0; | 359 isDirty = 0; |
355 } | 360 } |
LEFT | RIGHT |