Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterListener.js

Issue 29342974: Issue 4067 - Make filter "keys" generated for element hiding filters numeric (Closed)
Patch Set: Created May 24, 2016, 11:48 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
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.
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 subscription.filters.forEach(addFilter);
224 flushElemHide(); 249 flushElemHide();
225 } 250 }
226 } 251 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld