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