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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 ElemHide.remove(filter); | 210 ElemHide.remove(filter); |
211 else if (filter instanceof ElemHideEmulationFilter) | 211 else if (filter instanceof ElemHideEmulationFilter) |
212 ElemHideEmulation.remove(filter); | 212 ElemHideEmulation.remove(filter); |
213 else | 213 else |
214 ElemHideExceptions.remove(filter); | 214 ElemHideExceptions.remove(filter); |
215 } | 215 } |
216 else if (filter instanceof SnippetFilter) | 216 else if (filter instanceof SnippetFilter) |
217 Snippets.remove(filter); | 217 Snippets.remove(filter); |
218 } | 218 } |
219 | 219 |
220 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; | |
221 | |
222 function addSubscriptionFilters(subscription) | |
223 { | |
224 // We add filters using pseudo-random ordering. Reason is that ElemHide will | |
225 // assign consecutive filter IDs that might be visible to the website. The | |
226 // randomization makes sure that no conclusion can be made about the actual | |
227 // filters applying there. We have ten prime numbers to use as iteration step, | |
228 // any of those can be chosen as long as the array length isn't divisible by | |
229 // it. | |
230 let len = subscription.filterCount; | |
231 if (!len) | |
232 return; | |
233 | |
234 let current = (Math.random() * len) | 0; | |
235 let step; | |
236 do | |
237 { | |
238 step = primes[(Math.random() * primes.length) | 0]; | |
239 } while (len % step == 0); | |
240 | |
241 for (let i = 0; i < len; i++, current = (current + step) % len) | |
242 addFilter(subscription.filterAt(current)); | |
243 } | |
244 | |
245 function onSubscriptionAdded(subscription) | 220 function onSubscriptionAdded(subscription) |
246 { | 221 { |
247 FilterListener.setDirty(1); | 222 FilterListener.setDirty(1); |
248 | 223 |
249 if (!subscription.disabled) | 224 if (!subscription.disabled) |
250 addSubscriptionFilters(subscription); | 225 { |
| 226 for (let filter of subscription.filters()) |
| 227 addFilter(filter); |
| 228 } |
251 } | 229 } |
252 | 230 |
253 function onSubscriptionRemoved(subscription) | 231 function onSubscriptionRemoved(subscription) |
254 { | 232 { |
255 FilterListener.setDirty(1); | 233 FilterListener.setDirty(1); |
256 | 234 |
257 if (!subscription.disabled) | 235 if (!subscription.disabled) |
258 { | 236 { |
259 for (let filter of subscription.filters()) | 237 for (let filter of subscription.filters()) |
260 removeFilter(filter); | 238 removeFilter(filter); |
261 } | 239 } |
262 } | 240 } |
263 | 241 |
264 function onSubscriptionDisabled(subscription, newValue) | 242 function onSubscriptionDisabled(subscription, newValue) |
265 { | 243 { |
266 FilterListener.setDirty(1); | 244 FilterListener.setDirty(1); |
267 | 245 |
268 if (filterStorage.knownSubscriptions.has(subscription.url)) | 246 if (filterStorage.knownSubscriptions.has(subscription.url)) |
269 { | 247 { |
270 if (newValue == false) | 248 if (newValue == false) |
271 { | 249 { |
272 addSubscriptionFilters(subscription); | 250 for (let filter of subscription.filters()) |
| 251 addFilter(filter); |
273 } | 252 } |
274 else | 253 else |
275 { | 254 { |
276 for (let filter of subscription.filters()) | 255 for (let filter of subscription.filters()) |
277 removeFilter(filter); | 256 removeFilter(filter); |
278 } | 257 } |
279 } | 258 } |
280 } | 259 } |
281 | 260 |
282 function onSubscriptionUpdated(subscription, oldFilters) | 261 function onSubscriptionUpdated(subscription, oldFilters) |
283 { | 262 { |
284 FilterListener.setDirty(1); | 263 FilterListener.setDirty(1); |
285 | 264 |
286 if (!subscription.disabled && | 265 if (!subscription.disabled && |
287 filterStorage.knownSubscriptions.has(subscription.url)) | 266 filterStorage.knownSubscriptions.has(subscription.url)) |
288 { | 267 { |
289 for (let filter of oldFilters) | 268 for (let filter of oldFilters) |
290 removeFilter(filter); | 269 removeFilter(filter); |
291 | 270 |
292 addSubscriptionFilters(subscription); | 271 for (let filter of subscription.filters()) |
| 272 addFilter(filter); |
293 } | 273 } |
294 } | 274 } |
295 | 275 |
296 function onFilterHitCount(filter, newValue) | 276 function onFilterHitCount(filter, newValue) |
297 { | 277 { |
298 if (newValue == 0) | 278 if (newValue == 0) |
299 FilterListener.setDirty(0); | 279 FilterListener.setDirty(0); |
300 else | 280 else |
301 FilterListener.setDirty(0.002); | 281 FilterListener.setDirty(0.002); |
302 } | 282 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 323 |
344 defaultMatcher.clear(); | 324 defaultMatcher.clear(); |
345 ElemHide.clear(); | 325 ElemHide.clear(); |
346 ElemHideEmulation.clear(); | 326 ElemHideEmulation.clear(); |
347 ElemHideExceptions.clear(); | 327 ElemHideExceptions.clear(); |
348 Snippets.clear(); | 328 Snippets.clear(); |
349 | 329 |
350 for (let subscription of filterStorage.subscriptions()) | 330 for (let subscription of filterStorage.subscriptions()) |
351 { | 331 { |
352 if (!subscription.disabled) | 332 if (!subscription.disabled) |
353 addSubscriptionFilters(subscription); | 333 { |
| 334 for (let filter of subscription.filters()) |
| 335 addFilter(filter); |
| 336 } |
354 } | 337 } |
355 } | 338 } |
356 | 339 |
357 function onSave() | 340 function onSave() |
358 { | 341 { |
359 isDirty = 0; | 342 isDirty = 0; |
360 } | 343 } |
OLD | NEW |