Left: | ||
Right: |
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 14 matching lines...) Expand all Loading... | |
25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
27 | 27 |
28 const {filterStorage} = require("./filterStorage"); | 28 const {filterStorage} = require("./filterStorage"); |
29 const {filterNotifier} = require("./filterNotifier"); | 29 const {filterNotifier} = require("./filterNotifier"); |
30 const {ElemHide} = require("./elemHide"); | 30 const {ElemHide} = require("./elemHide"); |
31 const {ElemHideEmulation} = require("./elemHideEmulation"); | 31 const {ElemHideEmulation} = require("./elemHideEmulation"); |
32 const {ElemHideExceptions} = require("./elemHideExceptions"); | 32 const {ElemHideExceptions} = require("./elemHideExceptions"); |
33 const {Snippets} = require("./snippets"); | 33 const {Snippets} = require("./snippets"); |
34 const {defaultMatcher} = require("./matcher"); | 34 const {defaultMatcher} = require("./matcher"); |
35 const {ActiveFilter, RegExpFilter, | 35 const {Filter, ActiveFilter, RegExpFilter, |
36 ElemHideBase, ElemHideFilter, ElemHideEmulationFilter, | 36 ElemHideBase, ElemHideFilter, ElemHideEmulationFilter, |
37 SnippetFilter} = require("./filterClasses"); | 37 SnippetFilter} = require("./filterClasses"); |
38 const {SpecialSubscription} = require("./subscriptionClasses"); | 38 const {SpecialSubscription} = require("./subscriptionClasses"); |
39 const {Prefs} = require("prefs"); | 39 const {Prefs} = require("prefs"); |
40 | 40 |
41 /** | 41 /** |
42 * Increases on filter changes, filters will be saved if it exceeds 1. | 42 * Increases on filter changes, filters will be saved if it exceeds 1. |
43 * @type {number} | 43 * @type {number} |
44 */ | 44 */ |
45 let isDirty = 0; | 45 let isDirty = 0; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 return; | 232 return; |
233 | 233 |
234 let current = (Math.random() * len) | 0; | 234 let current = (Math.random() * len) | 0; |
235 let step; | 235 let step; |
236 do | 236 do |
237 { | 237 { |
238 step = primes[(Math.random() * primes.length) | 0]; | 238 step = primes[(Math.random() * primes.length) | 0]; |
239 } while (len % step == 0); | 239 } while (len % step == 0); |
240 | 240 |
241 for (let i = 0; i < len; i++, current = (current + step) % len) | 241 for (let i = 0; i < len; i++, current = (current + step) % len) |
242 addFilter(subscription.filterAt(current)); | 242 { |
243 let filter = Filter.fromText(subscription.filterTextAt(current)); | |
244 filter.addSubscription(subscription); | |
245 addFilter(filter); | |
246 } | |
243 } | 247 } |
244 | 248 |
245 function onSubscriptionAdded(subscription) | 249 function onSubscriptionAdded(subscription) |
246 { | 250 { |
247 FilterListener.setDirty(1); | 251 FilterListener.setDirty(1); |
248 | 252 |
249 if (!subscription.disabled) | 253 if (!subscription.disabled) |
250 addSubscriptionFilters(subscription); | 254 addSubscriptionFilters(subscription); |
251 } | 255 } |
252 | 256 |
253 function onSubscriptionRemoved(subscription) | 257 function onSubscriptionRemoved(subscription) |
254 { | 258 { |
255 FilterListener.setDirty(1); | 259 FilterListener.setDirty(1); |
256 | 260 |
257 if (!subscription.disabled) | 261 if (!subscription.disabled) |
258 { | 262 { |
259 for (let filter of subscription.filters()) | 263 for (let text of subscription.filterText()) |
260 removeFilter(filter); | 264 removeFilter(Filter.fromText(text)); |
hub
2018/11/30 01:18:07
here remove filter takes longer since we have to g
Manish Jethani
2018/11/30 07:28:05
Yes, this is a cost of this change, and by itself
hub
2019/01/03 20:22:48
Acknowledged.
| |
261 } | 265 } |
262 } | 266 } |
263 | 267 |
264 function onSubscriptionDisabled(subscription, newValue) | 268 function onSubscriptionDisabled(subscription, newValue) |
265 { | 269 { |
266 FilterListener.setDirty(1); | 270 FilterListener.setDirty(1); |
267 | 271 |
268 if (filterStorage.knownSubscriptions.has(subscription.url)) | 272 if (filterStorage.knownSubscriptions.has(subscription.url)) |
269 { | 273 { |
270 if (newValue == false) | 274 if (newValue == false) |
271 { | 275 { |
272 addSubscriptionFilters(subscription); | 276 addSubscriptionFilters(subscription); |
273 } | 277 } |
274 else | 278 else |
275 { | 279 { |
276 for (let filter of subscription.filters()) | 280 for (let text of subscription.filterText()) |
277 removeFilter(filter); | 281 removeFilter(Filter.fromText(text)); |
hub
2018/11/30 01:18:07
...so does disable subscription.
Manish Jethani
2018/11/30 07:28:05
See above.
| |
278 } | 282 } |
279 } | 283 } |
280 } | 284 } |
281 | 285 |
282 function onSubscriptionUpdated(subscription, oldFilters) | 286 function onSubscriptionUpdated(subscription, oldFilterText) |
283 { | 287 { |
284 FilterListener.setDirty(1); | 288 FilterListener.setDirty(1); |
285 | 289 |
286 if (!subscription.disabled && | 290 if (!subscription.disabled && |
287 filterStorage.knownSubscriptions.has(subscription.url)) | 291 filterStorage.knownSubscriptions.has(subscription.url)) |
288 { | 292 { |
289 for (let filter of oldFilters) | 293 for (let text of oldFilterText) |
290 removeFilter(filter); | 294 removeFilter(Filter.fromText(text)); |
291 | 295 |
292 addSubscriptionFilters(subscription); | 296 addSubscriptionFilters(subscription); |
293 } | 297 } |
294 } | 298 } |
295 | 299 |
296 function onFilterHitCount(filter, newValue) | 300 function onFilterHitCount(filter, newValue) |
297 { | 301 { |
298 if (newValue == 0) | 302 if (newValue == 0) |
299 FilterListener.setDirty(0); | 303 FilterListener.setDirty(0); |
300 else | 304 else |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 { | 355 { |
352 if (!subscription.disabled) | 356 if (!subscription.disabled) |
353 addSubscriptionFilters(subscription); | 357 addSubscriptionFilters(subscription); |
354 } | 358 } |
355 } | 359 } |
356 | 360 |
357 function onSave() | 361 function onSave() |
358 { | 362 { |
359 isDirty = 0; | 363 isDirty = 0; |
360 } | 364 } |
OLD | NEW |