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