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-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 var API = (function() | 18 "use strict"; |
| 19 |
| 20 let API = (() => |
19 { | 21 { |
20 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 22 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
21 var Filter = require("filterClasses").Filter; | 23 const {Filter} = require("filterClasses"); |
22 var Subscription = require("subscriptionClasses").Subscription; | 24 const {Subscription} = require("subscriptionClasses"); |
23 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; | 25 const {SpecialSubscription} = require("subscriptionClasses"); |
24 var FilterStorage = require("filterStorage").FilterStorage; | 26 const {FilterStorage} = require("filterStorage"); |
25 var defaultMatcher = require("matcher").defaultMatcher; | 27 const {defaultMatcher} = require("matcher"); |
26 var ElemHide = require("elemHide").ElemHide; | 28 const {ElemHide} = require("elemHide"); |
27 var Synchronizer = require("synchronizer").Synchronizer; | 29 const {Synchronizer} = require("synchronizer"); |
28 var Prefs = require("prefs").Prefs; | 30 const {Prefs} = require("prefs"); |
29 var checkForUpdates = require("updater").checkForUpdates; | 31 const {checkForUpdates} = require("updater"); |
30 var Notification = require("notification").Notification; | 32 const {Notification} = require("notification"); |
31 | 33 |
32 return { | 34 return { |
33 getFilterFromText: function(text) | 35 getFilterFromText(text) |
34 { | 36 { |
35 text = Filter.normalize(text); | 37 text = Filter.normalize(text); |
36 if (!text) | 38 if (!text) |
37 throw "Attempted to create a filter from empty text"; | 39 throw "Attempted to create a filter from empty text"; |
38 return Filter.fromText(text); | 40 return Filter.fromText(text); |
39 }, | 41 }, |
40 | 42 |
41 isListedFilter: function(filter) | 43 isListedFilter(filter) |
42 { | 44 { |
43 return filter.subscriptions.some(function(s) | 45 return filter.subscriptions.some(s => |
44 { | 46 { |
45 return (s instanceof SpecialSubscription && !s.disabled); | 47 return (s instanceof SpecialSubscription && !s.disabled); |
46 }); | 48 }); |
47 }, | 49 }, |
48 | 50 |
49 addFilterToList: function(filter) | 51 addFilterToList(filter) |
50 { | 52 { |
51 FilterStorage.addFilter(filter); | 53 FilterStorage.addFilter(filter); |
52 }, | 54 }, |
53 | 55 |
54 removeFilterFromList: function(filter) | 56 removeFilterFromList(filter) |
55 { | 57 { |
56 FilterStorage.removeFilter(filter); | 58 FilterStorage.removeFilter(filter); |
57 }, | 59 }, |
58 | 60 |
59 getListedFilters: function() | 61 getListedFilters() |
60 { | 62 { |
61 var filters = {}; | 63 let filters = {}; |
62 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | 64 for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
63 { | 65 { |
64 var subscription = FilterStorage.subscriptions[i]; | 66 let subscription = FilterStorage.subscriptions[i]; |
65 if (subscription instanceof SpecialSubscription) | 67 if (subscription instanceof SpecialSubscription) |
66 { | 68 { |
67 for (var j = 0; j < subscription.filters.length; j++) | 69 for (let j = 0; j < subscription.filters.length; j++) |
68 { | 70 { |
69 var filter = subscription.filters[j]; | 71 let filter = subscription.filters[j]; |
70 if (!(filter.text in filters)) | 72 if (!(filter.text in filters)) |
71 filters[filter.text] = filter; | 73 filters[filter.text] = filter; |
72 } | 74 } |
73 } | 75 } |
74 } | 76 } |
75 return Object.keys(filters).map(function(k) | 77 return Object.keys(filters).map(k => |
76 { | 78 { |
77 return filters[k]; | 79 return filters[k]; |
78 }); | 80 }); |
79 }, | 81 }, |
80 | 82 |
81 getSubscriptionFromUrl: function(url) | 83 getSubscriptionFromUrl(url) |
82 { | 84 { |
83 return Subscription.fromURL(url); | 85 return Subscription.fromURL(url); |
84 }, | 86 }, |
85 | 87 |
86 isListedSubscription: function(subscription) | 88 isListedSubscription(subscription) |
87 { | 89 { |
88 return subscription.url in FilterStorage.knownSubscriptions; | 90 return subscription.url in FilterStorage.knownSubscriptions; |
89 }, | 91 }, |
90 | 92 |
91 addSubscriptionToList: function(subscription) | 93 addSubscriptionToList(subscription) |
92 { | 94 { |
93 FilterStorage.addSubscription(subscription); | 95 FilterStorage.addSubscription(subscription); |
94 | 96 |
95 if (!subscription.lastDownload) | 97 if (!subscription.lastDownload) |
96 Synchronizer.execute(subscription); | 98 Synchronizer.execute(subscription); |
97 }, | 99 }, |
98 | 100 |
99 removeSubscriptionFromList: function(subscription) | 101 removeSubscriptionFromList(subscription) |
100 { | 102 { |
101 FilterStorage.removeSubscription(subscription); | 103 FilterStorage.removeSubscription(subscription); |
102 }, | 104 }, |
103 | 105 |
104 updateSubscription: function(subscription) | 106 updateSubscription(subscription) |
105 { | 107 { |
106 Synchronizer.execute(subscription); | 108 Synchronizer.execute(subscription); |
107 }, | 109 }, |
108 | 110 |
109 isSubscriptionUpdating: function(subscription) | 111 isSubscriptionUpdating(subscription) |
110 { | 112 { |
111 return Synchronizer.isExecuting(subscription.url); | 113 return Synchronizer.isExecuting(subscription.url); |
112 }, | 114 }, |
113 | 115 |
114 getListedSubscriptions: function() | 116 getListedSubscriptions() |
115 { | 117 { |
116 return FilterStorage.subscriptions.filter(function(s) | 118 return FilterStorage.subscriptions.filter(s => |
117 { | 119 { |
118 return !(s instanceof SpecialSubscription) | 120 return !(s instanceof SpecialSubscription); |
119 }); | 121 }); |
120 }, | 122 }, |
121 | 123 |
122 getRecommendedSubscriptions: function() | 124 getRecommendedSubscriptions() |
123 { | 125 { |
124 var subscriptions = require("subscriptions.xml"); | 126 let subscriptions = require("subscriptions.xml"); |
125 var result = []; | 127 let result = []; |
126 for (var i = 0; i < subscriptions.length; i++) | 128 for (let i = 0; i < subscriptions.length; i++) |
127 { | 129 { |
128 var subscription = Subscription.fromURL(subscriptions[i].url); | 130 let subscription = Subscription.fromURL(subscriptions[i].url); |
129 subscription.title = subscriptions[i].title; | 131 subscription.title = subscriptions[i].title; |
130 subscription.homepage = subscriptions[i].homepage; | 132 subscription.homepage = subscriptions[i].homepage; |
131 | 133 |
132 // These aren't normally properties of a Subscription object | 134 // These aren't normally properties of a Subscription object |
133 subscription.author = subscriptions[i].author; | 135 subscription.author = subscriptions[i].author; |
134 subscription.prefixes = subscriptions[i].prefixes; | 136 subscription.prefixes = subscriptions[i].prefixes; |
135 subscription.specialization = subscriptions[i].specialization; | 137 subscription.specialization = subscriptions[i].specialization; |
136 result.push(subscription); | 138 result.push(subscription); |
137 } | 139 } |
138 return result; | 140 return result; |
139 }, | 141 }, |
140 | 142 |
141 isAASubscription: function(subscription) | 143 isAASubscription(subscription) |
142 { | 144 { |
143 return subscription.url == Prefs.subscriptions_exceptionsurl; | 145 return subscription.url == Prefs.subscriptions_exceptionsurl; |
144 }, | 146 }, |
145 | 147 |
146 setAASubscriptionEnabled: function(enabled) | 148 setAASubscriptionEnabled(enabled) |
147 { | 149 { |
148 var aaSubscription = FilterStorage.subscriptions.find(API.isAASubscription
); | 150 let aaSubscription = FilterStorage.subscriptions.find( |
| 151 API.isAASubscription); |
149 if (!enabled) | 152 if (!enabled) |
150 { | 153 { |
151 if (aaSubscription && !aaSubscription.disabled) | 154 if (aaSubscription && !aaSubscription.disabled) |
152 aaSubscription.disabled = true; | 155 aaSubscription.disabled = true; |
153 return; | 156 return; |
154 } | 157 } |
155 if (!aaSubscription) | 158 if (!aaSubscription) |
156 { | 159 { |
157 aaSubscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl)
; | 160 aaSubscription = Subscription.fromURL( |
| 161 Prefs.subscriptions_exceptionsurl); |
158 FilterStorage.addSubscription(aaSubscription); | 162 FilterStorage.addSubscription(aaSubscription); |
159 } | 163 } |
160 if (aaSubscription.disabled) | 164 if (aaSubscription.disabled) |
161 aaSubscription.disabled = false; | 165 aaSubscription.disabled = false; |
162 if (!aaSubscription.lastDownload) | 166 if (!aaSubscription.lastDownload) |
163 Synchronizer.execute(aaSubscription); | 167 Synchronizer.execute(aaSubscription); |
164 }, | 168 }, |
165 | 169 |
166 isAASubscriptionEnabled: function() | 170 isAASubscriptionEnabled() |
167 { | 171 { |
168 var aaSubscription = FilterStorage.subscriptions.find(API.isAASubscription
); | 172 let aaSubscription = FilterStorage.subscriptions.find( |
| 173 API.isAASubscription); |
169 return aaSubscription && !aaSubscription.disabled; | 174 return aaSubscription && !aaSubscription.disabled; |
170 }, | 175 }, |
171 | 176 |
172 showNextNotification: function(url) | 177 showNextNotification(url) |
173 { | 178 { |
174 Notification.showNext(url); | 179 Notification.showNext(url); |
175 }, | 180 }, |
176 | 181 |
177 getNotificationTexts: function(notification) | 182 getNotificationTexts(notification) |
178 { | 183 { |
179 return Notification.getLocalizedTexts(notification); | 184 return Notification.getLocalizedTexts(notification); |
180 }, | 185 }, |
181 | 186 |
182 markNotificationAsShown: function(id) | 187 markNotificationAsShown(id) |
183 { | 188 { |
184 Notification.markAsShown(id); | 189 Notification.markAsShown(id); |
185 }, | 190 }, |
186 checkFilterMatch: function(url, contentTypeMask, documentUrl) | 191 checkFilterMatch(url, contentTypeMask, documentUrl) |
187 { | 192 { |
188 var requestHost = extractHostFromURL(url); | 193 let requestHost = extractHostFromURL(url); |
189 var documentHost = extractHostFromURL(documentUrl); | 194 let documentHost = extractHostFromURL(documentUrl); |
190 var thirdParty = isThirdParty(requestHost, documentHost); | 195 let thirdParty = isThirdParty(requestHost, documentHost); |
191 return defaultMatcher.matchesAny(url, contentTypeMask, documentHost, third
Party); | 196 return defaultMatcher.matchesAny( |
192 }, | 197 url, contentTypeMask, documentHost, thirdParty); |
193 | 198 }, |
194 getElementHidingSelectors: function(domain) | 199 |
195 { | 200 getElementHidingSelectors(domain) |
196 return ElemHide.getSelectorsForDomain(domain, ElemHide.ALL_MATCHING, false
); | 201 { |
197 }, | 202 return ElemHide.getSelectorsForDomain(domain, |
198 | 203 ElemHide.ALL_MATCHING, false); |
199 getPref: function(pref) | 204 }, |
| 205 |
| 206 getPref(pref) |
200 { | 207 { |
201 return Prefs[pref]; | 208 return Prefs[pref]; |
202 }, | 209 }, |
203 | 210 |
204 setPref: function(pref, value) | 211 setPref(pref, value) |
205 { | 212 { |
206 Prefs[pref] = value; | 213 Prefs[pref] = value; |
207 }, | 214 }, |
208 | 215 |
209 forceUpdateCheck: function(eventName) | 216 forceUpdateCheck(eventName) |
210 { | 217 { |
211 checkForUpdates(eventName ? _triggerEvent.bind(null, eventName) : null); | 218 checkForUpdates(eventName ? _triggerEvent.bind(null, eventName) : null); |
212 }, | 219 }, |
213 | 220 |
214 getHostFromUrl: function(url) | 221 getHostFromUrl(url) |
215 { | 222 { |
216 return extractHostFromURL(url); | 223 return extractHostFromURL(url); |
217 }, | 224 }, |
218 | 225 |
219 compareVersions: function(v1, v2) | 226 compareVersions(v1, v2) |
220 { | 227 { |
221 return Services.vc.compare(v1, v2); | 228 return Services.vc.compare(v1, v2); |
222 } | 229 } |
223 }; | 230 }; |
224 })(); | 231 })(); |
OLD | NEW |