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-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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (value != this._disabled) | 118 if (value != this._disabled) |
119 { | 119 { |
120 let oldValue = this._disabled; | 120 let oldValue = this._disabled; |
121 this._disabled = value; | 121 this._disabled = value; |
122 filterNotifier.emit("subscription.disabled", this, value, oldValue); | 122 filterNotifier.emit("subscription.disabled", this, value, oldValue); |
123 } | 123 } |
124 return this._disabled; | 124 return this._disabled; |
125 }, | 125 }, |
126 | 126 |
127 /** | 127 /** |
128 * Serializes the subscription to an array of strings for writing | 128 * Serializes the subscription for writing out on disk. |
129 * out on the disk. | |
130 * @yields {string} | 129 * @yields {string} |
131 */ | 130 */ |
132 *serialize() | 131 *serialize() |
133 { | 132 { |
| 133 let {url, type, _title, _fixedTitle, _disabled} = this; |
| 134 |
134 yield "[Subscription]"; | 135 yield "[Subscription]"; |
135 yield "url=" + this.url; | 136 yield "url=" + url; |
136 | 137 |
137 if (this.type) | 138 if (type) |
138 yield "type=" + this.type; | 139 yield "type=" + type; |
139 if (this._title) | 140 if (_title) |
140 yield "title=" + this._title; | 141 yield "title=" + _title; |
141 if (this._fixedTitle) | 142 if (_fixedTitle) |
142 yield "fixedTitle=true"; | 143 yield "fixedTitle=true"; |
143 if (this._disabled) | 144 if (_disabled) |
144 yield "disabled=true"; | 145 yield "disabled=true"; |
145 }, | 146 }, |
146 | 147 |
147 *serializeFilters() | 148 *serializeFilters() |
148 { | 149 { |
149 for (let filter of this.filters) | 150 let {filters} = this; |
| 151 |
| 152 yield "[Subscription filters]"; |
| 153 |
| 154 for (let filter of filters) |
150 yield filter.text.replace(/\[/g, "\\["); | 155 yield filter.text.replace(/\[/g, "\\["); |
151 }, | 156 }, |
152 | 157 |
153 toString() | 158 toString() |
154 { | 159 { |
155 return [...this.serialize()].join("\n"); | 160 return [...this.serialize()].join("\n"); |
156 } | 161 } |
157 }; | 162 }; |
158 | 163 |
159 /** | 164 /** |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 280 |
276 return false; | 281 return false; |
277 }, | 282 }, |
278 | 283 |
279 /** | 284 /** |
280 * See Subscription.serialize() | 285 * See Subscription.serialize() |
281 * @inheritdoc | 286 * @inheritdoc |
282 */ | 287 */ |
283 *serialize() | 288 *serialize() |
284 { | 289 { |
| 290 let {defaults, _lastDownload} = this; |
| 291 |
285 yield* Subscription.prototype.serialize.call(this); | 292 yield* Subscription.prototype.serialize.call(this); |
286 if (this.defaults && this.defaults.length) | 293 |
| 294 if (defaults) |
287 { | 295 { |
288 yield "defaults=" + | 296 yield "defaults=" + |
289 this.defaults.filter( | 297 defaults.filter( |
290 type => SpecialSubscription.defaultsMap.has(type) | 298 type => SpecialSubscription.defaultsMap.has(type) |
291 ).join(" ") | 299 ).join(" "); |
292 ; | 300 } |
293 } | 301 if (_lastDownload) |
294 if (this._lastDownload) | 302 yield "lastDownload=" + _lastDownload; |
295 yield "lastDownload=" + this._lastDownload; | |
296 } | 303 } |
297 }); | 304 }); |
298 | 305 |
299 SpecialSubscription.defaultsMap = new Map([ | 306 SpecialSubscription.defaultsMap = new Map([ |
300 ["whitelist", WhitelistFilter], | 307 ["whitelist", WhitelistFilter], |
301 ["blocking", BlockingFilter], | 308 ["blocking", BlockingFilter], |
302 ["elemhide", ElemHideBase] | 309 ["elemhide", ElemHideBase] |
303 ]); | 310 ]); |
304 | 311 |
305 /** | 312 /** |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 400 } |
394 return this._lastDownload; | 401 return this._lastDownload; |
395 }, | 402 }, |
396 | 403 |
397 /** | 404 /** |
398 * See Subscription.serialize() | 405 * See Subscription.serialize() |
399 * @inheritdoc | 406 * @inheritdoc |
400 */ | 407 */ |
401 *serialize() | 408 *serialize() |
402 { | 409 { |
| 410 let {_homepage, _lastDownload} = this; |
| 411 |
403 yield* Subscription.prototype.serialize.call(this); | 412 yield* Subscription.prototype.serialize.call(this); |
404 if (this._homepage) | 413 |
405 yield "homepage=" + this._homepage; | 414 if (_homepage) |
406 if (this._lastDownload) | 415 yield "homepage=" + _homepage; |
407 yield "lastDownload=" + this._lastDownload; | 416 if (_lastDownload) |
| 417 yield "lastDownload=" + _lastDownload; |
408 } | 418 } |
409 }); | 419 }); |
410 | 420 |
411 /** | 421 /** |
412 * Class for filter subscriptions updated externally (by other extension) | 422 * Class for filter subscriptions updated externally (by other extension) |
413 * @param {string} url see {@link Subscription Subscription()} | 423 * @param {string} url see {@link Subscription Subscription()} |
414 * @param {string} [title] see {@link Subscription Subscription()} | 424 * @param {string} [title] see {@link Subscription Subscription()} |
415 * @constructor | 425 * @constructor |
416 * @augments RegularSubscription | 426 * @augments RegularSubscription |
417 */ | 427 */ |
418 function ExternalSubscription(url, title) | 428 function ExternalSubscription(url, title) |
419 { | 429 { |
420 RegularSubscription.call(this, url, title); | 430 RegularSubscription.call(this, url, title); |
421 } | 431 } |
422 exports.ExternalSubscription = ExternalSubscription; | 432 exports.ExternalSubscription = ExternalSubscription; |
423 | 433 |
424 ExternalSubscription.prototype = extend(RegularSubscription, { | 434 ExternalSubscription.prototype = extend(RegularSubscription, { |
425 /** | 435 /** |
426 * See Subscription.serialize() | 436 * See Subscription.serialize() |
427 * @inheritdoc | 437 * @inheritdoc |
428 */ | 438 */ |
429 *serialize() | 439 *serialize() // eslint-disable-line require-yield |
430 { | 440 { |
431 yield new Error( | 441 throw new Error( |
432 "Unexpected call, external subscriptions should not be serialized" | 442 "Unexpected call, external subscriptions should not be serialized" |
433 ); | 443 ); |
434 } | 444 } |
435 }); | 445 }); |
436 | 446 |
437 /** | 447 /** |
438 * Class for filter subscriptions updated externally (by other extension) | 448 * Class for filter subscriptions updated externally (by other extension) |
439 * @param {string} url see {@link Subscription Subscription()} | 449 * @param {string} url see {@link Subscription Subscription()} |
440 * @param {string} [title] see {@link Subscription Subscription()} | 450 * @param {string} [title] see {@link Subscription Subscription()} |
441 * @constructor | 451 * @constructor |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 * @type {number} | 556 * @type {number} |
547 */ | 557 */ |
548 downloadCount: 0, | 558 downloadCount: 0, |
549 | 559 |
550 /** | 560 /** |
551 * See Subscription.serialize() | 561 * See Subscription.serialize() |
552 * @inheritdoc | 562 * @inheritdoc |
553 */ | 563 */ |
554 *serialize() | 564 *serialize() |
555 { | 565 { |
| 566 let {downloadStatus, lastSuccess, lastCheck, expires, |
| 567 softExpiration, errors, version, requiredVersion, |
| 568 downloadCount} = this; |
| 569 |
556 yield* RegularSubscription.prototype.serialize.call(this); | 570 yield* RegularSubscription.prototype.serialize.call(this); |
557 if (this.downloadStatus) | 571 |
558 yield "downloadStatus=" + this.downloadStatus; | 572 if (downloadStatus) |
559 if (this.lastSuccess) | 573 yield "downloadStatus=" + downloadStatus; |
560 yield "lastSuccess=" + this.lastSuccess; | 574 if (lastSuccess) |
561 if (this.lastCheck) | 575 yield "lastSuccess=" + lastSuccess; |
562 yield "lastCheck=" + this.lastCheck; | 576 if (lastCheck) |
563 if (this.expires) | 577 yield "lastCheck=" + lastCheck; |
564 yield "expires=" + this.expires; | 578 if (expires) |
565 if (this.softExpiration) | 579 yield "expires=" + expires; |
566 yield "softExpiration=" + this.softExpiration; | 580 if (softExpiration) |
567 if (this.errors) | 581 yield "softExpiration=" + softExpiration; |
568 yield "errors=" + this.errors; | 582 if (errors) |
569 if (this.version) | 583 yield "errors=" + errors; |
570 yield "version=" + this.version; | 584 if (version) |
571 if (this.requiredVersion) | 585 yield "version=" + version; |
572 yield "requiredVersion=" + this.requiredVersion; | 586 if (requiredVersion) |
573 if (this.downloadCount) | 587 yield "requiredVersion=" + requiredVersion; |
574 yield "downloadCount=" + this.downloadCount; | 588 if (downloadCount) |
| 589 yield "downloadCount=" + downloadCount; |
575 } | 590 } |
576 }); | 591 }); |
LEFT | RIGHT |