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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 Cu.import("resource://gre/modules/Services.jsm"); | 18 "use strict"; |
19 | 19 |
20 let {Utils} = require("utils"); | 20 const {Prefs} = require("prefs"); |
21 let {Prefs} = require("prefs"); | 21 const {ActiveFilter} = require("filterClasses"); |
22 let {ActiveFilter} = require("filterClasses"); | 22 const {FilterStorage} = require("filterStorage"); |
23 let {FilterStorage} = require("filterStorage"); | 23 const {FilterNotifier} = require("filterNotifier"); |
24 let {FilterNotifier} = require("filterNotifier"); | 24 const {Subscription} = require("subscriptionClasses"); |
25 let {Subscription} = require("subscriptionClasses"); | 25 const {Notification} = require("notification"); |
26 let {Notification} = require("notification"); | |
27 | 26 |
28 let ext; | 27 let ext; |
29 if (typeof window != "undefined" && window.ext) | 28 if (typeof window != "undefined" && window.ext) |
30 ext = window.ext; | 29 ({ext} = window); |
31 else | 30 else |
32 ext = require("ext_background"); | 31 ext = require("ext_background"); |
33 | 32 |
34 exports.initAntiAdblockNotification = function initAntiAdblockNotification() | 33 exports.initAntiAdblockNotification = function initAntiAdblockNotification() |
35 { | 34 { |
36 let notification = { | 35 let notification = { |
37 id: "antiadblock", | 36 id: "antiadblock", |
38 type: "question", | 37 type: "question", |
39 title: ext.i18n.getMessage("notification_antiadblock_title"), | 38 title: ext.i18n.getMessage("notification_antiadblock_title"), |
40 message: ext.i18n.getMessage("notification_antiadblock_message"), | 39 message: ext.i18n.getMessage("notification_antiadblock_message"), |
(...skipping 10 matching lines...) Expand all Loading... |
51 function addAntiAdblockNotification(subscription) | 50 function addAntiAdblockNotification(subscription) |
52 { | 51 { |
53 let urlFilters = []; | 52 let urlFilters = []; |
54 for (let filter of subscription.filters) | 53 for (let filter of subscription.filters) |
55 { | 54 { |
56 if (filter instanceof ActiveFilter) | 55 if (filter instanceof ActiveFilter) |
57 { | 56 { |
58 for (let domain in filter.domains) | 57 for (let domain in filter.domains) |
59 { | 58 { |
60 let urlFilter = "||" + domain + "^$document"; | 59 let urlFilter = "||" + domain + "^$document"; |
61 if (domain && filter.domains[domain] && urlFilters.indexOf(urlFilter)
== -1) | 60 if (domain && filter.domains[domain] && |
| 61 urlFilters.indexOf(urlFilter) == -1) |
62 urlFilters.push(urlFilter); | 62 urlFilters.push(urlFilter); |
63 } | 63 } |
64 } | 64 } |
65 } | 65 } |
66 notification.urlFilters = urlFilters; | 66 notification.urlFilters = urlFilters; |
67 Notification.addNotification(notification); | 67 Notification.addNotification(notification); |
68 Notification.addQuestionListener(notification.id, notificationListener); | 68 Notification.addQuestionListener(notification.id, notificationListener); |
69 } | 69 } |
70 | 70 |
71 function removeAntiAdblockNotification() | 71 function removeAntiAdblockNotification() |
72 { | 72 { |
73 Notification.removeNotification(notification); | 73 Notification.removeNotification(notification); |
74 Notification.removeQuestionListener(notification.id, notificationListener); | 74 Notification.removeQuestionListener(notification.id, notificationListener); |
75 } | 75 } |
76 | 76 |
77 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); | 77 let antiAdblockSubscription = Subscription.fromURL( |
78 if (subscription.lastDownload && subscription.disabled) | 78 Prefs.subscriptions_antiadblockurl |
79 addAntiAdblockNotification(subscription); | 79 ); |
| 80 if (antiAdblockSubscription.lastDownload && antiAdblockSubscription.disabled) |
| 81 addAntiAdblockNotification(antiAdblockSubscription); |
80 | 82 |
81 function onSubscriptionChange(subscription) | 83 function onSubscriptionChange(subscription) |
82 { | 84 { |
83 let url = Prefs.subscriptions_antiadblockurl; | 85 let url = Prefs.subscriptions_antiadblockurl; |
84 if (url != subscription.url) | 86 if (url != subscription.url) |
85 return; | 87 return; |
86 | 88 |
87 if (url in FilterStorage.knownSubscriptions && !subscription.disabled) | 89 if (url in FilterStorage.knownSubscriptions && !subscription.disabled) |
88 addAntiAdblockNotification(subscription); | 90 addAntiAdblockNotification(subscription); |
89 else | 91 else |
90 removeAntiAdblockNotification(); | 92 removeAntiAdblockNotification(); |
91 } | 93 } |
92 | 94 |
93 FilterNotifier.on("subscription.updated", onSubscriptionChange); | 95 FilterNotifier.on("subscription.updated", onSubscriptionChange); |
94 FilterNotifier.on("subscription.removed", onSubscriptionChange); | 96 FilterNotifier.on("subscription.removed", onSubscriptionChange); |
95 FilterNotifier.on("subscription.disabled", onSubscriptionChange); | 97 FilterNotifier.on("subscription.disabled", onSubscriptionChange); |
96 } | 98 }; |
OLD | NEW |