| 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 {ArrayLike} = require("coreUtils"); |  | 
| 22 const {Subscription, SpecialSubscription} = require("subscriptionClasses"); | 21 const {Subscription, SpecialSubscription} = require("subscriptionClasses"); | 
| 23 const {ActiveFilter} = require("filterClasses"); |  | 
| 24 const {Prefs} = require("prefs"); |  | 
| 25 | 22 | 
| 26 // Backwards compatibility | 23 // Backwards compatibility | 
| 27 FilterStorage.getGroupForFilter = FilterStorage.getSubscriptionForFilter; | 24 FilterStorage.getGroupForFilter = FilterStorage.getSubscriptionForFilter; | 
| 28 | 25 | 
| 29 /** | 26 /** | 
| 30  * 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 | 
| 31  * 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 | 
| 32  * need persistent references or element access by position you should use | 29  * need persistent references or element access by position you should use | 
| 33  * FilterStorage.subscriptionAt() instead. | 30  * FilterStorage.subscriptionAt() instead. | 
| 34  * @type {Iterable} | 31  * @type {Iterable} | 
| 35  */ | 32  */ | 
| 36 FilterStorage.subscriptions = { | 33 FilterStorage.subscriptions = { | 
| 37   [Symbol.iterator]: function*() | 34   *[Symbol.iterator]() | 
| 38   { | 35   { | 
| 39     for (let i = 0, l = FilterStorage.subscriptionCount; i < l; i++) | 36     for (let i = 0, l = FilterStorage.subscriptionCount; i < l; i++) | 
| 40     { | 37     { | 
| 41       let subscription = FilterStorage.subscriptionAt(i); | 38       let subscription = FilterStorage.subscriptionAt(i); | 
| 42       try | 39       try | 
| 43       { | 40       { | 
| 44         yield subscription; | 41         yield subscription; | 
| 45       } | 42       } | 
| 46       finally | 43       finally | 
| 47       { | 44       { | 
| 48         subscription.delete(); | 45         subscription.delete(); | 
| 49       } | 46       } | 
| 50     } | 47     } | 
| 51   } | 48   } | 
| 52 }; | 49 }; | 
| 53 | 50 | 
| 54 /** | 51 /** | 
| 55  * 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, | 
| 56  * creates one if none found. | 53  * creates one if none found. | 
| 57  * @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 | 
| 58  */ | 57  */ | 
| 59 FilterStorage.addFilter = function(filter) | 58 FilterStorage.addFilter = function(filter) | 
| 60 { | 59 { | 
| 61   for (let subscription of this.subscriptions) | 60   for (let subscription of this.subscriptions) | 
| 62     if (!subscription.disabled && subscription.indexOfFilter(filter) >= 0) | 61     if (!subscription.disabled && subscription.indexOfFilter(filter) >= 0) | 
| 63       return; | 62       return false; | 
| 64 | 63 | 
| 65   let subscription = this.getSubscriptionForFilter(filter); | 64   let subscription = this.getSubscriptionForFilter(filter); | 
| 66   if (!subscription) | 65   try | 
| 67   { | 66   { | 
| 68     subscription = Subscription.fromURL(null); | 67     if (!subscription) | 
| 69     subscription.makeDefaultFor(filter); | 68     { | 
| 70     this.addSubscription(subscription); | 69       subscription = Subscription.fromURL(null); | 
|  | 70       subscription.makeDefaultFor(filter); | 
|  | 71       this.addSubscription(subscription); | 
|  | 72     } | 
|  | 73     subscription.insertFilterAt(filter, subscription.filterCount); | 
| 71   } | 74   } | 
| 72   subscription.insertFilterAt(filter, subscription.filterCount); | 75   finally | 
| 73   subscription.delete(); | 76   { | 
|  | 77     if (subscription) | 
|  | 78       subscription.delete(); | 
|  | 79   } | 
| 74   return true; | 80   return true; | 
| 75 }; | 81 }; | 
| 76 | 82 | 
| 77 /** | 83 /** | 
| 78  * Removes a user-defined filter from the list | 84  * Removes a user-defined filter from the list | 
| 79  * @param {Filter} filter | 85  * @param {Filter} filter | 
| 80  */ | 86  */ | 
| 81 FilterStorage.removeFilter = function(filter) | 87 FilterStorage.removeFilter = function(filter) | 
| 82 { | 88 { | 
| 83   for (let subscription of this.subscriptions) | 89   for (let subscription of this.subscriptions) | 
| 84   { | 90   { | 
| 85     if (subscription instanceof SpecialSubscription) | 91     if (subscription instanceof SpecialSubscription) | 
| 86     { | 92     { | 
| 87       while (true) | 93       while (true) | 
| 88       { | 94       { | 
| 89         let index = subscription.indexOfFilter(filter); | 95         let index = subscription.indexOfFilter(filter); | 
| 90         if (index >= 0) | 96         if (index >= 0) | 
| 91           subscription.removeFilterAt(index); | 97           subscription.removeFilterAt(index); | 
| 92         else | 98         else | 
| 93           break; | 99           break; | 
| 94       } | 100       } | 
| 95     } | 101     } | 
| 96   } | 102   } | 
| 97 }; | 103 }; | 
| 98 | 104 | 
| 99 exports.FilterStorage = FilterStorage; | 105 exports.FilterStorage = FilterStorage; | 
| LEFT | RIGHT | 
|---|