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 |
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 Handles notifications. | 21 * @fileOverview Handles notifications. |
22 */ | 22 */ |
23 | 23 |
24 const {Prefs} = require("prefs"); | 24 const {Prefs} = require("prefs"); |
25 const {Downloader, Downloadable, | 25 const {Downloader, Downloadable, |
26 MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); | 26 MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); |
27 const {Utils} = require("utils"); | 27 const {Utils} = require("utils"); |
28 const {Matcher, defaultMatcher} = require("matcher"); | 28 const {Matcher, defaultMatcher} = require("matcher"); |
29 const {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses"); | 29 const {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses"); |
30 const {compareVersion} = require("coreUtils"); | |
31 | 30 |
32 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; | 31 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; |
33 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; | 32 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; |
34 const EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; | 33 const EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; |
35 const TYPE = { | 34 const TYPE = { |
36 information: 0, | 35 information: 0, |
37 question: 1, | 36 question: 1, |
38 relentless: 2, | 37 relentless: 2, |
39 critical: 3 | 38 critical: 3 |
40 }; | 39 }; |
(...skipping 18 matching lines...) Expand all Loading... |
59 { | 58 { |
60 if (locale in translations) | 59 if (locale in translations) |
61 return translations[locale]; | 60 return translations[locale]; |
62 | 61 |
63 let languagePart = locale.substring(0, locale.indexOf("-")); | 62 let languagePart = locale.substring(0, locale.indexOf("-")); |
64 if (languagePart && languagePart in translations) | 63 if (languagePart && languagePart in translations) |
65 return translations[languagePart]; | 64 return translations[languagePart]; |
66 | 65 |
67 let defaultLocale = "en-US"; | 66 let defaultLocale = "en-US"; |
68 return translations[defaultLocale]; | 67 return translations[defaultLocale]; |
| 68 } |
| 69 |
| 70 function parseVersionComponent(comp) |
| 71 { |
| 72 if (comp == "*") |
| 73 return Infinity; |
| 74 return parseInt(comp, 10) || 0; |
| 75 } |
| 76 |
| 77 function compareVersion(v1, v2) |
| 78 { |
| 79 let regexp = /^(.*?)([a-z].*)?$/i; |
| 80 let [, head1, tail1] = regexp.exec(v1); |
| 81 let [, head2, tail2] = regexp.exec(v2); |
| 82 let components1 = head1.split("."); |
| 83 let components2 = head2.split("."); |
| 84 |
| 85 for (let i = 0; i < components1.length || |
| 86 i < components2.length; i++) |
| 87 { |
| 88 let result = parseVersionComponent(components1[i]) - |
| 89 parseVersionComponent(components2[i]) || 0; |
| 90 |
| 91 if (result != 0) |
| 92 return result; |
| 93 } |
| 94 |
| 95 // Compare version suffix (e.g. 0.1alpha < 0.1b1 < 01.b2 < 0.1). |
| 96 // However, note that this is a simple string comparision, meaning: b10 < b2 |
| 97 if (tail1 == tail2) |
| 98 return 0; |
| 99 if (!tail1 || tail2 && tail1 > tail2) |
| 100 return 1; |
| 101 return -1; |
69 } | 102 } |
70 | 103 |
71 /** | 104 /** |
72 * The object providing actual downloading functionality. | 105 * The object providing actual downloading functionality. |
73 * @type {Downloader} | 106 * @type {Downloader} |
74 */ | 107 */ |
75 let downloader = null; | 108 let downloader = null; |
76 let localData = []; | 109 let localData = []; |
77 | 110 |
78 /** | 111 /** |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 else if (index != -1 && forceValue !== true) | 513 else if (index != -1 && forceValue !== true) |
481 categories.splice(index, 1); | 514 categories.splice(index, 1); |
482 | 515 |
483 // HACK: JSON values aren't saved unless they are assigned a | 516 // HACK: JSON values aren't saved unless they are assigned a |
484 // different object. | 517 // different object. |
485 Prefs.notifications_ignoredcategories = | 518 Prefs.notifications_ignoredcategories = |
486 JSON.parse(JSON.stringify(categories)); | 519 JSON.parse(JSON.stringify(categories)); |
487 } | 520 } |
488 }; | 521 }; |
489 Notification.init(); | 522 Notification.init(); |
LEFT | RIGHT |