| 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 |
| 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 /** | 20 /** |
| 21 * @fileOverview Definition of Subscription class and its subclasses. | 21 * @fileOverview Definition of Subscription class and its subclasses. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 const {ActiveFilter, BlockingFilter, | 24 const {Filter, ActiveFilter, BlockingFilter, |
| 25 WhitelistFilter, ElemHideBase} = require("./filterClasses"); | 25 WhitelistFilter, ElemHideBase} = require("./filterClasses"); |
| 26 const {filterNotifier} = require("./filterNotifier"); | 26 const {filterNotifier} = require("./filterNotifier"); |
| 27 const {extend} = require("./coreUtils"); | 27 const {extend} = require("./coreUtils"); |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Abstract base class for filter subscriptions | 30 * Abstract base class for filter subscriptions |
| 31 * | 31 * |
| 32 * @param {string} url download location of the subscription | 32 * @param {string} url download location of the subscription |
| 33 * @param {string} [title] title of the filter subscription | 33 * @param {string} [title] title of the filter subscription |
| 34 * @constructor | 34 * @constructor |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 { | 161 { |
| 162 yield* this._filterText; | 162 yield* this._filterText; |
| 163 }, | 163 }, |
| 164 | 164 |
| 165 /** | 165 /** |
| 166 * Yields the {@link Filter} object for each filter in the subscription. | 166 * Yields the {@link Filter} object for each filter in the subscription. |
| 167 * @yields {Filter} | 167 * @yields {Filter} |
| 168 */ | 168 */ |
| 169 *filters() | 169 *filters() |
| 170 { | 170 { |
| 171 yield* this._filters; | 171 for (let i = 0; i < this._filters.length; i++) |
| 172 yield this._filters[i] || Filter.fromText(this._filterText[i], false); |
| 172 }, | 173 }, |
| 173 | 174 |
| 174 /** | 175 /** |
| 175 * Returns the {@link Filter} object at the given 0-based index. | 176 * Returns the {@link Filter} object at the given 0-based index. |
| 176 * @param {number} index | 177 * @param {number} index |
| 177 * @returns {?Filter} | 178 * @returns {?Filter} |
| 178 */ | 179 */ |
| 179 filterAt(index) | 180 filterAt(index) |
| 180 { | 181 { |
| 181 return this._filters[index] || null; | 182 return this._filters[index] || |
| 183 (index >= 0 && index < this._filters.length ? |
| 184 Filter.fromText(this._filterText[index], false) : null); |
| 182 }, | 185 }, |
| 183 | 186 |
| 184 /** | 187 /** |
| 185 * Returns the 0-based index of the given filter. | 188 * Returns the 0-based index of the given filter. |
| 186 * @param {Filter} filter | 189 * @param {Filter} filter |
| 187 * @param {number} [fromIndex] The index from which to start the search. | 190 * @param {number} [fromIndex] The index from which to start the search. |
| 188 * @return {number} | 191 * @return {number} |
| 189 */ | 192 */ |
| 190 searchFilter(filter, fromIndex = 0) | 193 searchFilter(filter, fromIndex = 0) |
| 191 { | 194 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 260 |
| 258 this._filterTextLookup = null; | 261 this._filterTextLookup = null; |
| 259 }, | 262 }, |
| 260 | 263 |
| 261 /** | 264 /** |
| 262 * Clears any in-memory caches held by the object. | 265 * Clears any in-memory caches held by the object. |
| 263 * @package | 266 * @package |
| 264 */ | 267 */ |
| 265 clearCaches() | 268 clearCaches() |
| 266 { | 269 { |
| 270 for (let i = 0; i < this._filters.length; i++) |
| 271 { |
| 272 if (this._filters[i] && this._filters[i].ephemeral) |
| 273 this._filters[i] = null; |
| 274 } |
| 275 |
| 267 this._filterTextLookup = null; | 276 this._filterTextLookup = null; |
| 268 }, | 277 }, |
| 269 | 278 |
| 270 /** | 279 /** |
| 271 * Serializes the subscription for writing out on disk. | 280 * Serializes the subscription for writing out on disk. |
| 272 * @yields {string} | 281 * @yields {string} |
| 273 */ | 282 */ |
| 274 *serialize() | 283 *serialize() |
| 275 { | 284 { |
| 276 let {url, type, _title, _fixedTitle, _disabled} = this; | 285 let {url, type, _title, _fixedTitle, _disabled} = this; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 if (errors) | 734 if (errors) |
| 726 yield "errors=" + errors; | 735 yield "errors=" + errors; |
| 727 if (version) | 736 if (version) |
| 728 yield "version=" + version; | 737 yield "version=" + version; |
| 729 if (requiredVersion) | 738 if (requiredVersion) |
| 730 yield "requiredVersion=" + requiredVersion; | 739 yield "requiredVersion=" + requiredVersion; |
| 731 if (downloadCount) | 740 if (downloadCount) |
| 732 yield "downloadCount=" + downloadCount; | 741 yield "downloadCount=" + downloadCount; |
| 733 } | 742 } |
| 734 }); | 743 }); |
| OLD | NEW |