| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 let maxVersionKey = parameter + "MaxVersion"; | 191 let maxVersionKey = parameter + "MaxVersion"; |
| 192 return !((parameter in target && target[parameter] != name) || | 192 return !((parameter in target && target[parameter] != name) || |
| 193 (minVersionKey in target && Services.vc.compare(version, target[m
inVersionKey]) < 0) || | 193 (minVersionKey in target && Services.vc.compare(version, target[m
inVersionKey]) < 0) || |
| 194 (maxVersionKey in target && Services.vc.compare(version, target[m
axVersionKey]) > 0)); | 194 (maxVersionKey in target && Services.vc.compare(version, target[m
axVersionKey]) > 0)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 let remoteData = []; | 197 let remoteData = []; |
| 198 if (typeof Prefs.notificationdata.data == "object" && Prefs.notificationdata
.data.notifications instanceof Array) | 198 if (typeof Prefs.notificationdata.data == "object" && Prefs.notificationdata
.data.notifications instanceof Array) |
| 199 remoteData = Prefs.notificationdata.data.notifications; | 199 remoteData = Prefs.notificationdata.data.notifications; |
| 200 | 200 |
| 201 if (!(Prefs.notificationdata.shown instanceof Array)) | |
| 202 { | |
| 203 Prefs.notificationdata.shown = []; | |
| 204 saveNotificationData(); | |
| 205 } | |
| 206 | |
| 207 let notifications = localData.concat(remoteData); | 201 let notifications = localData.concat(remoteData); |
| 208 if (notifications.length === 0) | 202 if (notifications.length === 0) |
| 209 return null; | 203 return null; |
| 210 | 204 |
| 211 let {addonName, addonVersion, application, applicationVersion, platform, pla
tformVersion} = require("info"); | 205 let {addonName, addonVersion, application, applicationVersion, platform, pla
tformVersion} = require("info"); |
| 212 let notificationToShow = null; | 206 let notificationToShow = null; |
| 213 for (let notification of notifications) | 207 for (let notification of notifications) |
| 214 { | 208 { |
| 215 if (typeof notification.type === "undefined" || notification.type !== "cri
tical") | 209 if (typeof notification.type === "undefined" || notification.type !== "cri
tical") |
| 216 { | 210 { |
| 217 if (Prefs.notificationdata.shown.indexOf(notification.id) !== -1 | 211 let shown = Prefs.notificationdata.shown; |
| 218 || Prefs.notifications_ignoredcategories.indexOf("*") !== -1) | 212 if (shown instanceof Array && shown.indexOf(notification.id) != -1) |
| 213 continue; |
| 214 if (Prefs.notifications_ignoredcategories.indexOf("*") != -1) |
| 219 continue; | 215 continue; |
| 220 } | 216 } |
| 221 | 217 |
| 222 if (typeof url === "string" || notification.urlFilters instanceof Array) | 218 if (typeof url === "string" || notification.urlFilters instanceof Array) |
| 223 { | 219 { |
| 224 if (typeof url === "string" && notification.urlFilters instanceof Array) | 220 if (typeof url === "string" && notification.urlFilters instanceof Array) |
| 225 { | 221 { |
| 226 let matcher = new Matcher(); | 222 let matcher = new Matcher(); |
| 227 for (let urlFilter of notification.urlFilters) | 223 for (let urlFilter of notification.urlFilters) |
| 228 matcher.add(Filter.fromText(urlFilter)); | 224 matcher.add(Filter.fromText(urlFilter)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 for (let showListener of showListeners) | 266 for (let showListener of showListeners) |
| 271 showListener(notification); | 267 showListener(notification); |
| 272 }, | 268 }, |
| 273 | 269 |
| 274 /** | 270 /** |
| 275 * Marks a notification as shown. | 271 * Marks a notification as shown. |
| 276 * @param {String} id ID of the notification to be marked as shown | 272 * @param {String} id ID of the notification to be marked as shown |
| 277 */ | 273 */ |
| 278 markAsShown: function(id) | 274 markAsShown: function(id) |
| 279 { | 275 { |
| 280 if (Prefs.notificationdata.shown.indexOf(id) > -1) | 276 var data = Prefs.notificationdata; |
| 277 |
| 278 if (!(data.shown instanceof Array)) |
| 279 data.shown = []; |
| 280 if (data.shown.indexOf(id) != -1) |
| 281 return; | 281 return; |
| 282 | 282 |
| 283 Prefs.notificationdata.shown.push(id); | 283 data.shown.push(id); |
| 284 saveNotificationData(); | 284 saveNotificationData(); |
| 285 }, | 285 }, |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * Localizes the texts of the supplied notification. | 288 * Localizes the texts of the supplied notification. |
| 289 * @param {Object} notification notification to translate | 289 * @param {Object} notification notification to translate |
| 290 * @param {String} locale the target locale (optional, defaults to the | 290 * @param {String} locale the target locale (optional, defaults to the |
| 291 * application locale) | 291 * application locale) |
| 292 * @return {Object} the translated texts | 292 * @return {Object} the translated texts |
| 293 */ | 293 */ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 Prefs.notifications_showui = true; | 384 Prefs.notifications_showui = true; |
| 385 } | 385 } |
| 386 else if (index != -1 && forceValue !== true) | 386 else if (index != -1 && forceValue !== true) |
| 387 categories.splice(index, 1); | 387 categories.splice(index, 1); |
| 388 | 388 |
| 389 // HACK: JSON values aren't saved unless they are assigned a different objec
t. | 389 // HACK: JSON values aren't saved unless they are assigned a different objec
t. |
| 390 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories
)); | 390 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories
)); |
| 391 } | 391 } |
| 392 }; | 392 }; |
| 393 Notification.init(); | 393 Notification.init(); |
| OLD | NEW |