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