| Index: lib/filterListener.js |
| =================================================================== |
| --- a/lib/filterListener.js |
| +++ b/lib/filterListener.js |
| @@ -209,16 +209,41 @@ function removeFilter(filter) |
| { |
| if (filter instanceof CSSPropertyFilter) |
| CSSRules.remove(filter); |
| else |
| ElemHide.remove(filter); |
| } |
| } |
| +const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; |
| + |
| +function addFilters(filters) |
| +{ |
| + // We add filters using pseudo-random ordering. Reason is that ElemHide will |
| + // assign consecutive filter IDs that might be visible to the website. The |
| + // randomization makes sure that no conclusion can be made about the actual |
| + // filters applying there. We have ten prime numbers to use as iteration step, |
| + // any of those can be chosen as long as the array length isn't divisible by |
| + // it. |
| + let len = filters.length; |
| + if (!len) |
| + return; |
| + |
| + let current = (Math.random() * len) | 0; |
| + let step; |
| + do |
| + { |
| + step = primes[(Math.random() * primes.length) | 0]; |
| + } while (len % step == 0); |
| + |
| + for (let i = 0; i < len; i++, current = (current + step) % len) |
|
kzar
2016/05/24 12:36:49
I didn't intuitively understand that this should w
Wladimir Palant
2016/05/24 12:49:50
That's because 61%6 happens to be 1. On the other
kzar
2016/05/24 12:57:45
Acknowledged.
|
| + addFilter(filters[current]); |
| +} |
| + |
| function onSubscriptionAdded(subscription) |
| { |
| FilterListener.setDirty(1); |
| if (!subscription.disabled) |
| { |
| subscription.filters.forEach(addFilter); |
| flushElemHide(); |
| @@ -318,16 +343,16 @@ function onLoad() |
| { |
| isDirty = 0; |
| defaultMatcher.clear(); |
| ElemHide.clear(); |
| CSSRules.clear(); |
| for (let subscription of FilterStorage.subscriptions) |
| if (!subscription.disabled) |
| - subscription.filters.forEach(addFilter); |
| + addFilters(subscription.filters); |
| flushElemHide(); |
| } |
| function onSave() |
| { |
| isDirty = 0; |
| } |