Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/antiadblockInit.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Patch Set: Fix imports in antiadblockInit.js Created March 14, 2017, 9:01 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/.eslintrc.json ('k') | messageResponder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
kzar 2017/03/14 10:57:36 I just noticed this gives me a no-unused-vars erro
Wladimir Palant 2017/03/14 11:14:57 This seems to be a left-over, even though I don't
kzar 2017/03/15 03:16:58 Done.
21 let {Prefs} = require("prefs"); 21
22 let {ActiveFilter} = require("filterClasses"); 22 const {Prefs} = require("prefs");
23 let {FilterStorage} = require("filterStorage"); 23 const {ActiveFilter} = require("filterClasses");
24 let {FilterNotifier} = require("filterNotifier"); 24 const {FilterStorage} = require("filterStorage");
25 let {Subscription} = require("subscriptionClasses"); 25 const {FilterNotifier} = require("filterNotifier");
26 let {Notification} = require("notification"); 26 const {Subscription} = require("subscriptionClasses");
27 const {Notification} = require("notification");
27 28
28 let ext; 29 let ext;
29 if (typeof window != "undefined" && window.ext) 30 if (typeof window != "undefined" && window.ext)
30 ext = window.ext; 31 ({ext} = window);
31 else 32 else
32 ext = require("ext_background"); 33 ext = require("ext_background");
33 34
34 exports.initAntiAdblockNotification = function initAntiAdblockNotification() 35 exports.initAntiAdblockNotification = function initAntiAdblockNotification()
35 { 36 {
36 let notification = { 37 let notification = {
37 id: "antiadblock", 38 id: "antiadblock",
38 type: "question", 39 type: "question",
39 title: ext.i18n.getMessage("notification_antiadblock_title"), 40 title: ext.i18n.getMessage("notification_antiadblock_title"),
40 message: ext.i18n.getMessage("notification_antiadblock_message"), 41 message: ext.i18n.getMessage("notification_antiadblock_message"),
(...skipping 10 matching lines...) Expand all
51 function addAntiAdblockNotification(subscription) 52 function addAntiAdblockNotification(subscription)
52 { 53 {
53 let urlFilters = []; 54 let urlFilters = [];
54 for (let filter of subscription.filters) 55 for (let filter of subscription.filters)
55 { 56 {
56 if (filter instanceof ActiveFilter) 57 if (filter instanceof ActiveFilter)
57 { 58 {
58 for (let domain in filter.domains) 59 for (let domain in filter.domains)
59 { 60 {
60 let urlFilter = "||" + domain + "^$document"; 61 let urlFilter = "||" + domain + "^$document";
61 if (domain && filter.domains[domain] && urlFilters.indexOf(urlFilter) == -1) 62 if (domain && filter.domains[domain] &&
63 urlFilters.indexOf(urlFilter) == -1)
62 urlFilters.push(urlFilter); 64 urlFilters.push(urlFilter);
63 } 65 }
64 } 66 }
65 } 67 }
66 notification.urlFilters = urlFilters; 68 notification.urlFilters = urlFilters;
67 Notification.addNotification(notification); 69 Notification.addNotification(notification);
68 Notification.addQuestionListener(notification.id, notificationListener); 70 Notification.addQuestionListener(notification.id, notificationListener);
69 } 71 }
70 72
71 function removeAntiAdblockNotification() 73 function removeAntiAdblockNotification()
72 { 74 {
73 Notification.removeNotification(notification); 75 Notification.removeNotification(notification);
74 Notification.removeQuestionListener(notification.id, notificationListener); 76 Notification.removeQuestionListener(notification.id, notificationListener);
75 } 77 }
76 78
77 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); 79 let antiAdblockSubscription = Subscription.fromURL(
78 if (subscription.lastDownload && subscription.disabled) 80 Prefs.subscriptions_antiadblockurl
79 addAntiAdblockNotification(subscription); 81 );
82 if (antiAdblockSubscription.lastDownload && antiAdblockSubscription.disabled)
83 addAntiAdblockNotification(antiAdblockSubscription);
80 84
81 function onSubscriptionChange(subscription) 85 function onSubscriptionChange(subscription)
82 { 86 {
83 let url = Prefs.subscriptions_antiadblockurl; 87 let url = Prefs.subscriptions_antiadblockurl;
84 if (url != subscription.url) 88 if (url != subscription.url)
85 return; 89 return;
86 90
87 if (url in FilterStorage.knownSubscriptions && !subscription.disabled) 91 if (url in FilterStorage.knownSubscriptions && !subscription.disabled)
88 addAntiAdblockNotification(subscription); 92 addAntiAdblockNotification(subscription);
89 else 93 else
90 removeAntiAdblockNotification(); 94 removeAntiAdblockNotification();
91 } 95 }
92 96
93 FilterNotifier.on("subscription.updated", onSubscriptionChange); 97 FilterNotifier.on("subscription.updated", onSubscriptionChange);
94 FilterNotifier.on("subscription.removed", onSubscriptionChange); 98 FilterNotifier.on("subscription.removed", onSubscriptionChange);
95 FilterNotifier.on("subscription.disabled", onSubscriptionChange); 99 FilterNotifier.on("subscription.disabled", onSubscriptionChange);
96 } 100 };
OLDNEW
« no previous file with comments | « lib/.eslintrc.json ('k') | messageResponder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld