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

Delta Between Two Patch Sets: lib/antiadblockInit.js

Issue 29773630: Issue 5761 - Changes require paths to relative (Closed) Base URL: https://hg.adblockplus.org/adblockplusui/
Left Patch Set: Address PS1 comment Created May 18, 2018, 5:18 p.m.
Right Patch Set: Address PS2 comment Created July 31, 2018, 6:46 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | messageResponder.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 const {Prefs} = require("../../lib/prefs"); 20 const {Prefs} = require("../../lib/prefs");
21 const {ActiveFilter} = require("../../adblockpluscore/lib/filterClasses"); 21 const {ActiveFilter} = require("../../adblockpluscore/lib/filterClasses");
22 const {FilterStorage} = require("../../adblockpluscore/lib/filterStorage"); 22 const {FilterStorage} = require("../../adblockpluscore/lib/filterStorage");
23 const {FilterNotifier} = require("../../adblockpluscore/lib/filterNotifier"); 23 const {FilterNotifier} = require("../../adblockpluscore/lib/filterNotifier");
24 const {Subscription} = require("../../adblockpluscore/lib/subscriptionClasses"); 24 const {Subscription} = require("../../adblockpluscore/lib/subscriptionClasses");
25 const {Notification} = require("../../adblockpluscore/lib/notification"); 25 const {Notification} = require("../../adblockpluscore/lib/notification");
26 26
27 exports.initAntiAdblockNotification = function initAntiAdblockNotification() 27 exports.initAntiAdblockNotification = function initAntiAdblockNotification()
28 { 28 {
29 let notification = { 29 const notification = {
30 id: "antiadblock", 30 id: "antiadblock",
31 type: "question", 31 type: "question",
32 title: browser.i18n.getMessage("notification_antiadblock_title"), 32 title: browser.i18n.getMessage("notification_antiadblock_title"),
33 message: browser.i18n.getMessage("notification_antiadblock_message"), 33 message: browser.i18n.getMessage("notification_antiadblock_message"),
34 urlFilters: [] 34 urlFilters: []
35 }; 35 };
36 36
37 function notificationListener(approved) 37 function notificationListener(approved)
38 { 38 {
39 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); 39 const subanti = Prefs.subscriptions_antiadblockurl;
40 if (subscription.url in FilterStorage.knownSubscriptions) 40 const subscription = Subscription.fromURL(subanti);
41 if (FilterStorage.knownSubscriptions.has(subscription.url))
41 subscription.disabled = !approved; 42 subscription.disabled = !approved;
42 } 43 }
43 44
44 function addAntiAdblockNotification(subscription) 45 function addAntiAdblockNotification(subscription)
45 { 46 {
46 let urlFilters = []; 47 const urlFilters = [];
47 for (let filter of subscription.filters) 48 for (const filter of subscription.filters)
48 { 49 {
49 if (filter instanceof ActiveFilter && filter.domains) 50 if (filter instanceof ActiveFilter && filter.domains)
50 { 51 {
51 for (let [domain, included] of filter.domains) 52 for (const [domain, included] of filter.domains)
52 { 53 {
53 let urlFilter = "||" + domain + "^$document"; 54 const urlFilter = "||" + domain + "^$document";
54 if (domain && included && urlFilters.indexOf(urlFilter) == -1) 55 if (domain && included && urlFilters.indexOf(urlFilter) == -1)
55 urlFilters.push(urlFilter); 56 urlFilters.push(urlFilter);
56 } 57 }
57 } 58 }
58 } 59 }
59 notification.urlFilters = urlFilters; 60 notification.urlFilters = urlFilters;
60 Notification.addNotification(notification); 61 Notification.addNotification(notification);
61 Notification.addQuestionListener(notification.id, notificationListener); 62 Notification.addQuestionListener(notification.id, notificationListener);
62 } 63 }
63 64
64 function removeAntiAdblockNotification() 65 function removeAntiAdblockNotification()
65 { 66 {
66 Notification.removeNotification(notification); 67 Notification.removeNotification(notification);
67 Notification.removeQuestionListener(notification.id, notificationListener); 68 Notification.removeQuestionListener(notification.id, notificationListener);
68 } 69 }
69 70
70 let antiAdblockSubscription = Subscription.fromURL( 71 const antiAdblockSubscription = Subscription.fromURL(
71 Prefs.subscriptions_antiadblockurl 72 Prefs.subscriptions_antiadblockurl
72 ); 73 );
73 if (antiAdblockSubscription.lastDownload && antiAdblockSubscription.disabled) 74 if (antiAdblockSubscription.lastDownload && antiAdblockSubscription.disabled)
74 addAntiAdblockNotification(antiAdblockSubscription); 75 addAntiAdblockNotification(antiAdblockSubscription);
75 76
76 function onSubscriptionChange(subscription) 77 function onSubscriptionChange(subscription)
77 { 78 {
78 let url = Prefs.subscriptions_antiadblockurl; 79 const url = Prefs.subscriptions_antiadblockurl;
79 if (url != subscription.url) 80 if (url != subscription.url)
80 return; 81 return;
81 82
82 if (url in FilterStorage.knownSubscriptions && subscription.disabled) 83 if (FilterStorage.knownSubscriptions.has(url) && subscription.disabled)
83 addAntiAdblockNotification(subscription); 84 addAntiAdblockNotification(subscription);
84 else 85 else
85 removeAntiAdblockNotification(); 86 removeAntiAdblockNotification();
86 } 87 }
87 88
88 FilterNotifier.on("subscription.updated", onSubscriptionChange); 89 FilterNotifier.on("subscription.updated", onSubscriptionChange);
89 FilterNotifier.on("subscription.removed", onSubscriptionChange); 90 FilterNotifier.on("subscription.removed", onSubscriptionChange);
90 FilterNotifier.on("subscription.disabled", onSubscriptionChange); 91 FilterNotifier.on("subscription.disabled", onSubscriptionChange);
91 }; 92 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld