Left: | ||
Right: |
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 (function(global) | 18 "use strict"; |
19 | |
19 { | 20 { |
20 if (!global.ext) | 21 var ext = ext || require("ext_background"); |
21 global.ext = require("ext_background"); | |
22 | 22 |
23 var port = require("messaging").port; | 23 let port = require("messaging").port; |
Sebastian Noack
2017/01/17 17:30:16
Also what is about using destructing here?
kzar
2017/01/18 05:50:32
Done.
| |
24 var Prefs = require("prefs").Prefs; | 24 let Prefs = require("prefs").Prefs; |
25 var Utils = require("utils").Utils; | 25 let Utils = require("utils").Utils; |
26 var FilterStorage = require("filterStorage").FilterStorage; | 26 let FilterStorage = require("filterStorage").FilterStorage; |
27 var FilterNotifier = require("filterNotifier").FilterNotifier; | 27 let FilterNotifier = require("filterNotifier").FilterNotifier; |
28 var defaultMatcher = require("matcher").defaultMatcher; | 28 let defaultMatcher = require("matcher").defaultMatcher; |
29 var ElemHideEmulation = require("elemHideEmulation").ElemHideEmulation; | 29 let ElemHideEmulation = require("elemHideEmulation").ElemHideEmulation; |
30 var NotificationStorage = require("notification").Notification; | 30 let NotificationStorage = require("notification").Notification; |
31 | 31 |
32 var filterClasses = require("filterClasses"); | 32 let filterClasses = require("filterClasses"); |
33 var Filter = filterClasses.Filter; | 33 let Filter = filterClasses.Filter; |
34 var BlockingFilter = filterClasses.BlockingFilter; | 34 let BlockingFilter = filterClasses.BlockingFilter; |
35 var RegExpFilter = filterClasses.RegExpFilter; | 35 let RegExpFilter = filterClasses.RegExpFilter; |
36 var Synchronizer = require("synchronizer").Synchronizer; | 36 let Synchronizer = require("synchronizer").Synchronizer; |
37 | 37 |
38 var info = require("info"); | 38 let info = require("info"); |
39 var subscriptionClasses = require("subscriptionClasses"); | 39 let subscriptionClasses = require("subscriptionClasses"); |
40 var Subscription = subscriptionClasses.Subscription; | 40 let Subscription = subscriptionClasses.Subscription; |
41 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; | 41 let DownloadableSubscription = subscriptionClasses.DownloadableSubscription; |
42 var SpecialSubscription = subscriptionClasses.SpecialSubscription; | 42 let SpecialSubscription = subscriptionClasses.SpecialSubscription; |
43 | 43 |
44 // Some modules doesn't exist on Firefox. Moreover, | 44 // Some modules doesn't exist on Firefox. Moreover, |
45 // require() throws an exception on Firefox in that case. | 45 // require() throws an exception on Firefox in that case. |
46 // However, try/catch causes the whole function to to be | 46 // However, try/catch causes the whole function to to be |
47 // deoptimized on V8. So we wrap it into another function. | 47 // deoptimized on V8. So we wrap it into another function. |
48 function tryRequire(module) | 48 function tryRequire(module) |
49 { | 49 { |
50 try | 50 try |
51 { | 51 { |
52 return require(module); | 52 return require(module); |
53 } | 53 } |
54 catch (e) | 54 catch (e) |
55 { | 55 { |
56 return null; | 56 return null; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 function convertObject(keys, obj) | 60 function convertObject(keys, obj) |
61 { | 61 { |
62 var result = {}; | 62 let result = {}; |
63 for (var i = 0; i < keys.length; i++) | 63 for (let key of keys) |
64 { | 64 { |
65 var key = keys[i]; | |
66 if (key in obj) | 65 if (key in obj) |
67 result[key] = obj[key]; | 66 result[key] = obj[key]; |
68 } | 67 } |
69 return result; | 68 return result; |
70 } | 69 } |
71 | 70 |
72 function convertSubscription(subscription) | 71 function convertSubscription(subscription) |
73 { | 72 { |
74 var obj = convertObject(["disabled", "downloadStatus", "homepage", | 73 let obj = convertObject(["disabled", "downloadStatus", "homepage", |
75 "lastDownload", "title", "url"], subscription); | 74 "lastDownload", "title", "url"], subscription); |
76 obj.isDownloading = Synchronizer.isExecuting(subscription.url); | 75 obj.isDownloading = Synchronizer.isExecuting(subscription.url); |
77 return obj; | 76 return obj; |
78 } | 77 } |
79 | 78 |
80 var convertFilter = convertObject.bind(null, ["text"]); | 79 let convertFilter = convertObject.bind(null, ["text"]); |
81 | 80 |
82 var changeListeners = new global.ext.PageMap(); | 81 let changeListeners = new ext.PageMap(); |
83 var listenedPreferences = Object.create(null); | 82 let listenedPreferences = Object.create(null); |
84 var listenedFilterChanges = Object.create(null); | 83 let listenedFilterChanges = Object.create(null); |
85 var messageTypes = { | 84 let messageTypes = { |
86 "app": "app.respond", | 85 "app": "app.respond", |
87 "filter": "filters.respond", | 86 "filter": "filters.respond", |
88 "pref": "prefs.respond", | 87 "pref": "prefs.respond", |
89 "subscription": "subscriptions.respond" | 88 "subscription": "subscriptions.respond" |
90 }; | 89 }; |
91 | 90 |
92 function sendMessage(type, action) | 91 function sendMessage(type, action) |
93 { | 92 { |
94 var pages = changeListeners.keys(); | 93 let pages = changeListeners.keys(); |
95 if (pages.length == 0) | 94 if (pages.length == 0) |
96 return; | 95 return; |
97 | 96 |
98 var args = []; | 97 let args = []; |
99 for (var i = 2; i < arguments.length; i++) | 98 for (let i = 2; i < arguments.length; i++) |
100 { | 99 { |
101 var arg = arguments[i]; | 100 let arg = arguments[i]; |
102 if (arg instanceof Subscription) | 101 if (arg instanceof Subscription) |
103 args.push(convertSubscription(arg)); | 102 args.push(convertSubscription(arg)); |
104 else if (arg instanceof Filter) | 103 else if (arg instanceof Filter) |
105 args.push(convertFilter(arg)); | 104 args.push(convertFilter(arg)); |
106 else | 105 else |
107 args.push(arg); | 106 args.push(arg); |
108 } | 107 } |
109 | 108 |
110 for (var j = 0; j < pages.length; j++) | 109 for (let page of pages) |
111 { | 110 { |
112 var page = pages[j]; | 111 let filters = changeListeners.get(page); |
113 var filters = changeListeners.get(page); | 112 let actions = filters[type]; |
114 var actions = filters[type]; | |
115 if (actions && actions.indexOf(action) != -1) | 113 if (actions && actions.indexOf(action) != -1) |
116 { | 114 { |
117 page.sendMessage({ | 115 page.sendMessage({ |
118 type: messageTypes[type], | 116 type: messageTypes[type], |
119 action: action, | 117 action: action, |
120 args: args | 118 args: args |
121 }); | 119 }); |
122 } | 120 } |
123 } | 121 } |
124 } | 122 } |
125 | 123 |
126 function addFilterListeners(type, actions) | 124 function addFilterListeners(type, actions) |
127 { | 125 { |
128 actions.forEach(function(action) | 126 for (let action of actions) |
129 { | 127 { |
130 var name; | 128 let name; |
131 if (type == "filter" && action == "loaded") | 129 if (type == "filter" && action == "loaded") |
132 name = "load"; | 130 name = "load"; |
133 else | 131 else |
134 name = type + "." + action; | 132 name = type + "." + action; |
135 | 133 |
136 if (!(name in listenedFilterChanges)) | 134 if (!(name in listenedFilterChanges)) |
137 { | 135 { |
138 listenedFilterChanges[name] = null; | 136 listenedFilterChanges[name] = null; |
139 FilterNotifier.on(name, function() | 137 FilterNotifier.on(name, function() |
140 { | 138 { |
141 var args = [type, action]; | 139 let args = [type, action]; |
142 for (var i = 0; i < arguments.length; i++) | 140 for (let arg of arguments) |
143 args.push(arguments[i]); | 141 args.push(arg); |
144 sendMessage.apply(null, args); | 142 sendMessage.apply(null, args); |
145 }); | 143 }); |
146 } | 144 } |
147 }); | 145 }; |
148 } | 146 } |
149 | 147 |
150 function getListenerFilters(page) | 148 function getListenerFilters(page) |
151 { | 149 { |
152 var listenerFilters = changeListeners.get(page); | 150 let listenerFilters = changeListeners.get(page); |
153 if (!listenerFilters) | 151 if (!listenerFilters) |
154 { | 152 { |
155 listenerFilters = Object.create(null); | 153 listenerFilters = Object.create(null); |
156 changeListeners.set(page, listenerFilters); | 154 changeListeners.set(page, listenerFilters); |
157 } | 155 } |
158 return listenerFilters; | 156 return listenerFilters; |
159 } | 157 } |
160 | 158 |
161 port.on("app.get", (message, sender) => | 159 port.on("app.get", (message, sender) => |
162 { | 160 { |
163 if (message.what == "issues") | 161 if (message.what == "issues") |
164 { | 162 { |
165 var subscriptionInit = tryRequire("subscriptionInit"); | 163 let subscriptionInit = tryRequire("subscriptionInit"); |
166 return { | 164 return { |
167 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false, | 165 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false, |
168 legacySafariVersion: (info.platform == "safari" && ( | 166 legacySafariVersion: (info.platform == "safari" && ( |
169 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforel oad breaks websites in Safari 5 | 167 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforel oad breaks websites in Safari 5 |
170 Services.vc.compare(info.platformVersion, "6.1") == 0 || // extensi ons are broken in 6.1 and 7.0 | 168 Services.vc.compare(info.platformVersion, "6.1") == 0 || // extensi ons are broken in 6.1 and 7.0 |
171 Services.vc.compare(info.platformVersion, "7.0") == 0)) | 169 Services.vc.compare(info.platformVersion, "7.0") == 0)) |
172 }; | 170 }; |
173 } | 171 } |
174 | 172 |
175 if (message.what == "doclink") | 173 if (message.what == "doclink") |
176 return Utils.getDocLink(message.link); | 174 return Utils.getDocLink(message.link); |
177 | 175 |
178 if (message.what == "localeInfo") | 176 if (message.what == "localeInfo") |
179 { | 177 { |
180 var bidiDir; | 178 let bidiDir; |
181 if ("chromeRegistry" in Utils) | 179 if ("chromeRegistry" in Utils) |
182 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr "; | 180 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr "; |
183 else | 181 else |
184 bidiDir = ext.i18n.getMessage("@@bidi_dir"); | 182 bidiDir = ext.i18n.getMessage("@@bidi_dir"); |
185 | 183 |
186 return {locale: Utils.appLocale, bidiDir: bidiDir}; | 184 return {locale: Utils.appLocale, bidiDir: bidiDir}; |
187 } | 185 } |
188 | 186 |
189 if (message.what == "features") | 187 if (message.what == "features") |
190 { | 188 { |
(...skipping 14 matching lines...) Expand all Loading... | |
205 }); | 203 }); |
206 | 204 |
207 port.on("app.open", (message, sender) => | 205 port.on("app.open", (message, sender) => |
208 { | 206 { |
209 if (message.what == "options") | 207 if (message.what == "options") |
210 ext.showOptions(); | 208 ext.showOptions(); |
211 }); | 209 }); |
212 | 210 |
213 port.on("filters.add", (message, sender) => | 211 port.on("filters.add", (message, sender) => |
214 { | 212 { |
215 var result = require("filterValidation").parseFilter(message.text); | 213 let result = require("filterValidation").parseFilter(message.text); |
216 var errors = []; | 214 let errors = []; |
217 if (result.error) | 215 if (result.error) |
218 errors.push(result.error.toString()); | 216 errors.push(result.error.toString()); |
219 else if (result.filter) | 217 else if (result.filter) |
220 FilterStorage.addFilter(result.filter); | 218 FilterStorage.addFilter(result.filter); |
221 | 219 |
222 return errors; | 220 return errors; |
223 }); | 221 }); |
224 | 222 |
225 port.on("filters.blocked", (message, sender) => | 223 port.on("filters.blocked", (message, sender) => |
226 { | 224 { |
227 var filter = defaultMatcher.matchesAny(message.url, | 225 let filter = defaultMatcher.matchesAny(message.url, |
228 RegExpFilter.typeMap[message.requestType], message.docDomain, | 226 RegExpFilter.typeMap[message.requestType], message.docDomain, |
229 message.thirdParty); | 227 message.thirdParty); |
230 | 228 |
231 return filter instanceof BlockingFilter; | 229 return filter instanceof BlockingFilter; |
232 }); | 230 }); |
233 | 231 |
234 port.on("filters.get", (message, sender) => | 232 port.on("filters.get", (message, sender) => |
235 { | 233 { |
236 if (message.what == "elemhideemulation") | 234 if (message.what == "elemhideemulation") |
237 { | 235 { |
238 var filters = []; | 236 let filters = []; |
239 var checkWhitelisted = require("whitelisting").checkWhitelisted; | 237 let checkWhitelisted = require("whitelisting").checkWhitelisted; |
240 | 238 |
241 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, | 239 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, |
242 RegExpFilter.typeMap.DOCUMENT | | 240 RegExpFilter.typeMap.DOCUMENT | |
243 RegExpFilter.typeMap.ELEMHIDE)) | 241 RegExpFilter.typeMap.ELEMHIDE)) |
244 { | 242 { |
245 var hostname = sender.frame.url.hostname; | 243 let hostname = sender.frame.url.hostname; |
246 filters = ElemHideEmulation.getRulesForDomain(hostname); | 244 filters = ElemHideEmulation.getRulesForDomain(hostname); |
247 filters = filters.map(function(filter) | 245 filters = filters.map(filter => |
248 { | 246 { |
249 return { | 247 return { |
250 selector: filter.selector, | 248 selector: filter.selector, |
251 text: filter.text | 249 text: filter.text |
252 }; | 250 }; |
253 }); | 251 }); |
254 } | 252 } |
255 return filters; | 253 return filters; |
256 } | 254 } |
257 | 255 |
258 var subscription = Subscription.fromURL(message.subscriptionUrl); | 256 let subscription = Subscription.fromURL(message.subscriptionUrl); |
259 if (!subscription) | 257 if (!subscription) |
260 return []; | 258 return []; |
261 | 259 |
262 return subscription.filters.map(convertFilter); | 260 return subscription.filters.map(convertFilter); |
263 }); | 261 }); |
264 | 262 |
265 port.on("filters.importRaw", (message, sender) => | 263 port.on("filters.importRaw", (message, sender) => |
266 { | 264 { |
267 var result = require("filterValidation").parseFilters(message.text); | 265 let result = require("filterValidation").parseFilters(message.text); |
268 var errors = []; | 266 let errors = []; |
269 for (var i = 0; i < result.errors.length; i++) | 267 for (let error of result.errors) |
270 { | 268 { |
271 var error = result.errors[i]; | |
272 if (error.type != "unexpected-filter-list-header") | 269 if (error.type != "unexpected-filter-list-header") |
273 errors.push(error.toString()); | 270 errors.push(error.toString()); |
274 } | 271 } |
275 | 272 |
276 if (errors.length > 0) | 273 if (errors.length > 0) |
277 return errors; | 274 return errors; |
278 | 275 |
279 var seenFilter = Object.create(null); | 276 let seenFilter = Object.create(null); |
280 for (var i = 0; i < result.filters.length; i++) | 277 for (let filter of result.filters) |
281 { | 278 { |
282 var filter = result.filters[i]; | |
283 FilterStorage.addFilter(filter); | 279 FilterStorage.addFilter(filter); |
284 seenFilter[filter.text] = null; | 280 seenFilter[filter.text] = null; |
285 } | 281 } |
286 | 282 |
287 if (!message.removeExisting) | 283 if (!message.removeExisting) |
288 return errors; | 284 return errors; |
289 | 285 |
290 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | 286 for (let subscription of FilterStorage.subscriptions) |
291 { | 287 { |
292 var subscription = FilterStorage.subscriptions[i]; | |
293 if (!(subscription instanceof SpecialSubscription)) | 288 if (!(subscription instanceof SpecialSubscription)) |
294 continue; | 289 continue; |
295 | 290 |
296 for (var j = subscription.filters.length - 1; j >= 0; j--) | 291 for (let j = subscription.filters.length - 1; j >= 0; j--) |
297 { | 292 { |
298 var filter = subscription.filters[j]; | 293 let filter = subscription.filters[j]; |
299 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) | 294 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
300 continue; | 295 continue; |
301 | 296 |
302 if (!(filter.text in seenFilter)) | 297 if (!(filter.text in seenFilter)) |
303 FilterStorage.removeFilter(filter); | 298 FilterStorage.removeFilter(filter); |
304 } | 299 } |
305 } | 300 } |
306 | 301 |
307 return errors; | 302 return errors; |
308 }); | 303 }); |
309 | 304 |
310 port.on("filters.listen", (message, sender) => | 305 port.on("filters.listen", (message, sender) => |
311 { | 306 { |
312 getListenerFilters(sender.page).filter = message.filter; | 307 getListenerFilters(sender.page).filter = message.filter; |
313 addFilterListeners("filter", message.filter); | 308 addFilterListeners("filter", message.filter); |
314 }); | 309 }); |
315 | 310 |
316 port.on("filters.remove", (message, sender) => | 311 port.on("filters.remove", (message, sender) => |
317 { | 312 { |
318 var filter = Filter.fromText(message.text); | 313 let filter = Filter.fromText(message.text); |
319 var subscription = null; | 314 let subscription = null; |
320 if (message.subscriptionUrl) | 315 if (message.subscriptionUrl) |
321 subscription = Subscription.fromURL(message.subscriptionUrl); | 316 subscription = Subscription.fromURL(message.subscriptionUrl); |
322 | 317 |
323 if (!subscription) | 318 if (!subscription) |
324 FilterStorage.removeFilter(filter); | 319 FilterStorage.removeFilter(filter); |
325 else | 320 else |
326 FilterStorage.removeFilter(filter, subscription, message.index); | 321 FilterStorage.removeFilter(filter, subscription, message.index); |
327 }); | 322 }); |
328 | 323 |
329 port.on("prefs.get", (message, sender) => | 324 port.on("prefs.get", (message, sender) => |
330 { | 325 { |
331 return Prefs[message.key]; | 326 return Prefs[message.key]; |
332 }); | 327 }); |
333 | 328 |
334 port.on("prefs.listen", (message, sender) => | 329 port.on("prefs.listen", (message, sender) => |
335 { | 330 { |
336 getListenerFilters(sender.page).pref = message.filter; | 331 getListenerFilters(sender.page).pref = message.filter; |
337 message.filter.forEach(function(preference) | 332 for (let preference of message.filter) |
338 { | 333 { |
339 if (!(preference in listenedPreferences)) | 334 if (!(preference in listenedPreferences)) |
340 { | 335 { |
341 listenedPreferences[preference] = null; | 336 listenedPreferences[preference] = null; |
342 Prefs.on(preference, function() | 337 Prefs.on(preference, () => |
343 { | 338 { |
344 sendMessage("pref", preference, Prefs[preference]); | 339 sendMessage("pref", preference, Prefs[preference]); |
345 }); | 340 }); |
346 } | 341 } |
347 }); | 342 }); |
348 }); | 343 }); |
349 | 344 |
350 port.on("prefs.toggle", (message, sender) => | 345 port.on("prefs.toggle", (message, sender) => |
351 { | 346 { |
352 if (message.key == "notifications_ignoredcategories") | 347 if (message.key == "notifications_ignoredcategories") |
353 NotificationStorage.toggleIgnoreCategory("*"); | 348 NotificationStorage.toggleIgnoreCategory("*"); |
354 else | 349 else |
355 Prefs[message.key] = !Prefs[message.key]; | 350 Prefs[message.key] = !Prefs[message.key]; |
356 }); | 351 }); |
357 | 352 |
358 port.on("subscriptions.add", (message, sender) => | 353 port.on("subscriptions.add", (message, sender) => |
359 { | 354 { |
360 var subscription = Subscription.fromURL(message.url); | 355 let subscription = Subscription.fromURL(message.url); |
361 if ("title" in message) | 356 if ("title" in message) |
362 subscription.title = message.title; | 357 subscription.title = message.title; |
363 if ("homepage" in message) | 358 if ("homepage" in message) |
364 subscription.homepage = message.homepage; | 359 subscription.homepage = message.homepage; |
365 | 360 |
366 if (message.confirm) | 361 if (message.confirm) |
367 { | 362 { |
368 ext.showOptions(function() | 363 ext.showOptions(() => |
369 { | 364 { |
370 sendMessage("app", "addSubscription", subscription); | 365 sendMessage("app", "addSubscription", subscription); |
371 }); | 366 }); |
372 } | 367 } |
373 else | 368 else |
374 { | 369 { |
375 subscription.disabled = false; | 370 subscription.disabled = false; |
376 FilterStorage.addSubscription(subscription); | 371 FilterStorage.addSubscription(subscription); |
377 | 372 |
378 if (subscription instanceof DownloadableSubscription && !subscription.last Download) | 373 if (subscription instanceof DownloadableSubscription && !subscription.last Download) |
379 Synchronizer.execute(subscription); | 374 Synchronizer.execute(subscription); |
380 } | 375 } |
381 }); | 376 }); |
382 | 377 |
383 port.on("subscriptions.get", (message, sender) => | 378 port.on("subscriptions.get", (message, sender) => |
384 { | 379 { |
385 var subscriptions = FilterStorage.subscriptions.filter(function(s) | 380 let subscriptions = FilterStorage.subscriptions.filter(s => |
386 { | 381 { |
387 if (message.ignoreDisabled && s.disabled) | 382 if (message.ignoreDisabled && s.disabled) |
388 return false; | 383 return false; |
389 if (s instanceof DownloadableSubscription && message.downloadable) | 384 if (s instanceof DownloadableSubscription && message.downloadable) |
390 return true; | 385 return true; |
391 if (s instanceof SpecialSubscription && message.special) | 386 if (s instanceof SpecialSubscription && message.special) |
392 return true; | 387 return true; |
393 return false; | 388 return false; |
394 }); | 389 }); |
395 | 390 |
396 return subscriptions.map(convertSubscription); | 391 return subscriptions.map(convertSubscription); |
397 }); | 392 }); |
398 | 393 |
399 port.on("subscriptions.listen", (message, sender) => | 394 port.on("subscriptions.listen", (message, sender) => |
400 { | 395 { |
401 getListenerFilters(sender.page).subscription = message.filter; | 396 getListenerFilters(sender.page).subscription = message.filter; |
402 addFilterListeners("subscription", message.filter); | 397 addFilterListeners("subscription", message.filter); |
403 }); | 398 }); |
404 | 399 |
405 port.on("subscriptions.remove", (message, sender) => | 400 port.on("subscriptions.remove", (message, sender) => |
406 { | 401 { |
407 var subscription = Subscription.fromURL(message.url); | 402 let subscription = Subscription.fromURL(message.url); |
408 if (subscription.url in FilterStorage.knownSubscriptions) | 403 if (subscription.url in FilterStorage.knownSubscriptions) |
409 FilterStorage.removeSubscription(subscription); | 404 FilterStorage.removeSubscription(subscription); |
410 }); | 405 }); |
411 | 406 |
412 port.on("subscriptions.toggle", (message, sender) => | 407 port.on("subscriptions.toggle", (message, sender) => |
413 { | 408 { |
414 var subscription = Subscription.fromURL(message.url); | 409 let subscription = Subscription.fromURL(message.url); |
415 if (subscription.url in FilterStorage.knownSubscriptions) | 410 if (subscription.url in FilterStorage.knownSubscriptions) |
416 { | 411 { |
417 if (subscription.disabled || message.keepInstalled) | 412 if (subscription.disabled || message.keepInstalled) |
418 subscription.disabled = !subscription.disabled; | 413 subscription.disabled = !subscription.disabled; |
419 else | 414 else |
420 FilterStorage.removeSubscription(subscription); | 415 FilterStorage.removeSubscription(subscription); |
421 } | 416 } |
422 else | 417 else |
423 { | 418 { |
424 subscription.disabled = false; | 419 subscription.disabled = false; |
425 subscription.title = message.title; | 420 subscription.title = message.title; |
426 subscription.homepage = message.homepage; | 421 subscription.homepage = message.homepage; |
427 FilterStorage.addSubscription(subscription); | 422 FilterStorage.addSubscription(subscription); |
428 if (!subscription.lastDownload) | 423 if (!subscription.lastDownload) |
429 Synchronizer.execute(subscription); | 424 Synchronizer.execute(subscription); |
430 } | 425 } |
431 }); | 426 }); |
432 | 427 |
433 port.on("subscriptions.update", (message, sender) => | 428 port.on("subscriptions.update", (message, sender) => |
434 { | 429 { |
435 var subscriptions = message.url ? [Subscription.fromURL(message.url)] : | 430 let subscriptions = message.url ? [Subscription.fromURL(message.url)] : |
436 FilterStorage.subscriptions; | 431 FilterStorage.subscriptions; |
437 for (var i = 0; i < subscriptions.length; i++) | 432 for (let subscription of subscriptions) |
438 { | 433 { |
439 var subscription = subscriptions[i]; | |
440 if (subscription instanceof DownloadableSubscription) | 434 if (subscription instanceof DownloadableSubscription) |
441 Synchronizer.execute(subscription, true); | 435 Synchronizer.execute(subscription, true); |
442 } | 436 } |
443 }); | 437 }); |
444 })(this); | 438 } |
OLD | NEW |