LEFT | RIGHT |
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-2017 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const {FilterStorage} = require("compiled"); | 20 const {FilterStorage} = require("compiled"); |
21 const {Subscription, SpecialSubscription} = require("subscriptionClasses"); | 21 const {Subscription, SpecialSubscription} = require("subscriptionClasses"); |
22 const {ActiveFilter} = require("filterClasses"); | |
23 | 22 |
24 // Backwards compatibility | 23 // Backwards compatibility |
25 FilterStorage.getGroupForFilter = FilterStorage.getSubscriptionForFilter; | 24 FilterStorage.getGroupForFilter = FilterStorage.getSubscriptionForFilter; |
26 | 25 |
27 /** | 26 /** |
28 * This property allows iterating over the list of subscriptions. It will delete | 27 * This property allows iterating over the list of subscriptions. It will delete |
29 * references automatically at the end of the current loop iteration. If you | 28 * references automatically at the end of the current loop iteration. If you |
30 * need persistent references or element access by position you should use | 29 * need persistent references or element access by position you should use |
31 * FilterStorage.subscriptionAt() instead. | 30 * FilterStorage.subscriptionAt() instead. |
32 * @type {Iterable} | 31 * @type {Iterable} |
33 */ | 32 */ |
34 FilterStorage.subscriptions = { | 33 FilterStorage.subscriptions = { |
35 [Symbol.iterator]: function*() | 34 *[Symbol.iterator]() |
36 { | 35 { |
37 for (let i = 0, l = FilterStorage.subscriptionCount; i < l; i++) | 36 for (let i = 0, l = FilterStorage.subscriptionCount; i < l; i++) |
38 { | 37 { |
39 let subscription = FilterStorage.subscriptionAt(i); | 38 let subscription = FilterStorage.subscriptionAt(i); |
40 try | 39 try |
41 { | 40 { |
42 yield subscription; | 41 yield subscription; |
43 } | 42 } |
44 finally | 43 finally |
45 { | 44 { |
46 subscription.delete(); | 45 subscription.delete(); |
47 } | 46 } |
48 } | 47 } |
49 } | 48 } |
50 }; | 49 }; |
51 | 50 |
52 /** | 51 /** |
53 * Adds a user-defined filter to the most suitable subscription in the list, | 52 * Adds a user-defined filter to the most suitable subscription in the list, |
54 * creates one if none found. | 53 * creates one if none found. |
55 * @param {Filter} filter | 54 * @param {Filter} filter |
| 55 * @returns {boolean} |
| 56 * false if the filter was already in the list and no adding was performed |
56 */ | 57 */ |
57 FilterStorage.addFilter = function(filter) | 58 FilterStorage.addFilter = function(filter) |
58 { | 59 { |
59 for (let subscription of this.subscriptions) | 60 for (let subscription of this.subscriptions) |
60 if (!subscription.disabled && subscription.indexOfFilter(filter) >= 0) | 61 if (!subscription.disabled && subscription.indexOfFilter(filter) >= 0) |
61 return; | 62 return false; |
62 | 63 |
63 let subscription = this.getSubscriptionForFilter(filter); | 64 let subscription = this.getSubscriptionForFilter(filter); |
64 try | 65 try |
65 { | 66 { |
66 if (!subscription) | 67 if (!subscription) |
67 { | 68 { |
68 subscription = Subscription.fromURL(null); | 69 subscription = Subscription.fromURL(null); |
69 subscription.makeDefaultFor(filter); | 70 subscription.makeDefaultFor(filter); |
70 this.addSubscription(subscription); | 71 this.addSubscription(subscription); |
71 } | 72 } |
(...skipping 23 matching lines...) Expand all Loading... |
95 if (index >= 0) | 96 if (index >= 0) |
96 subscription.removeFilterAt(index); | 97 subscription.removeFilterAt(index); |
97 else | 98 else |
98 break; | 99 break; |
99 } | 100 } |
100 } | 101 } |
101 } | 102 } |
102 }; | 103 }; |
103 | 104 |
104 exports.FilterStorage = FilterStorage; | 105 exports.FilterStorage = FilterStorage; |
LEFT | RIGHT |