| 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 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 let languagePart = locale.substring(0, locale.indexOf("-")); | 63 let languagePart = locale.substring(0, locale.indexOf("-")); |
| 64 if (languagePart && languagePart in translations) | 64 if (languagePart && languagePart in translations) |
| 65 return translations[languagePart]; | 65 return translations[languagePart]; |
| 66 | 66 |
| 67 let defaultLocale = "en-US"; | 67 let defaultLocale = "en-US"; |
| 68 return translations[defaultLocale]; | 68 return translations[defaultLocale]; |
| 69 } | 69 } |
| 70 | 70 |
| 71 function parseVersionComponent(comp) | 71 function parseVersionComponent(comp) |
| 72 { | 72 { |
| 73 if (comp == "*") | 73 if (comp === "*") |
| 74 return Infinity; | 74 return Infinity; |
| 75 return parseInt(comp, 10) || 0; | 75 return parseInt(comp, 10) || 0; |
| 76 } | 76 } |
| 77 | 77 |
| 78 function compareVersion(v1, v2) | 78 function compareVersion(v1, v2) |
| 79 { | 79 { |
| 80 let regexp = /^(.*?)([a-z].*)?$/i; | 80 let regexp = /^(.*?)([a-z].*)?$/i; |
| 81 let [, head1, tail1] = regexp.exec(v1); | 81 let [, head1, tail1] = regexp.exec(v1); |
| 82 let [, head2, tail2] = regexp.exec(v2); | 82 let [, head2, tail2] = regexp.exec(v2); |
| 83 let components1 = head1.split("."); | 83 let components1 = head1.split("."); |
| 84 let components2 = head2.split("."); | 84 let components2 = head2.split("."); |
| 85 | 85 |
| 86 for (let i = 0; i < components1.length || | 86 for (let i = 0; i < components1.length || |
| 87 i < components2.length; i++) | 87 i < components2.length; i++) |
| 88 { | 88 { |
| 89 let result = parseVersionComponent(components1[i]) - | 89 let result = parseVersionComponent(components1[i]) - |
| 90 parseVersionComponent(components2[i]) || 0; | 90 parseVersionComponent(components2[i]) || 0; |
| 91 | 91 |
| 92 if (result != 0) | 92 if (result !== 0) |
| 93 return result; | 93 return result; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Compare version suffix (e.g. 0.1alpha < 0.1b1 < 01.b2 < 0.1). | 96 // Compare version suffix (e.g. 0.1alpha < 0.1b1 < 01.b2 < 0.1). |
| 97 // However, note that this is a simple string comparision, meaning: b10 < b2 | 97 // However, note that this is a simple string comparision, meaning: b10 < b2 |
| 98 if (tail1 == tail2) | 98 if (tail1 == tail2) |
| 99 return 0; | 99 return 0; |
| 100 if (!tail1 || tail2 && tail1 > tail2) | 100 if (!tail1 || tail2 && tail1 > tail2) |
| 101 return 1; | 101 return 1; |
| 102 return -1; | 102 return -1; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 saveNotificationData(); | 204 saveNotificationData(); |
| 205 }, | 205 }, |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * Adds a listener for notifications to be shown. | 208 * Adds a listener for notifications to be shown. |
| 209 * @param {Function} listener Listener to be invoked when a notification is | 209 * @param {Function} listener Listener to be invoked when a notification is |
| 210 * to be shown | 210 * to be shown |
| 211 */ | 211 */ |
| 212 addShowListener(listener) | 212 addShowListener(listener) |
| 213 { | 213 { |
| 214 if (showListeners.indexOf(listener) == -1) | 214 if (showListeners.indexOf(listener) === -1) |
| 215 showListeners.push(listener); | 215 showListeners.push(listener); |
| 216 }, | 216 }, |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * Removes the supplied listener. | 219 * Removes the supplied listener. |
| 220 * @param {Function} listener Listener that was added via addShowListener() | 220 * @param {Function} listener Listener that was added via addShowListener() |
| 221 */ | 221 */ |
| 222 removeShowListener(listener) | 222 removeShowListener(listener) |
| 223 { | 223 { |
| 224 let index = showListeners.indexOf(listener); | 224 let index = showListeners.indexOf(listener); |
| 225 if (index != -1) | 225 if (index !== -1) |
| 226 showListeners.splice(index, 1); | 226 showListeners.splice(index, 1); |
| 227 }, | 227 }, |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * Determines which notification is to be shown next. | 230 * Determines which notification is to be shown next. |
| 231 * @param {string} url URL to match notifications to (optional) | 231 * @param {string} url URL to match notifications to (optional) |
| 232 * @return {Object} notification to be shown, or null if there is none | 232 * @return {Object} notification to be shown, or null if there is none |
| 233 */ | 233 */ |
| 234 _getNextToShow(url) | 234 _getNextToShow(url) |
| 235 { | 235 { |
| 236 let remoteData = []; | 236 let remoteData = []; |
| 237 if (typeof Prefs.notificationdata.data == "object" && | 237 if (typeof Prefs.notificationdata.data === "object" && |
| 238 Prefs.notificationdata.data.notifications instanceof Array) | 238 Prefs.notificationdata.data.notifications instanceof Array) |
| 239 { | 239 { |
| 240 remoteData = Prefs.notificationdata.data.notifications; | 240 remoteData = Prefs.notificationdata.data.notifications; |
| 241 } | 241 } |
| 242 | 242 |
| 243 let notifications = localData.concat(remoteData); | 243 let notifications = localData.concat(remoteData); |
| 244 if (notifications.length === 0) | 244 if (notifications.length === 0) |
| 245 return null; | 245 return null; |
| 246 | 246 |
| 247 const {addonName, addonVersion, application, | 247 const {addonName, addonVersion, application, |
| 248 applicationVersion, platform, platformVersion} = require("info"); | 248 applicationVersion, platform, platformVersion} = require("info"); |
| 249 | 249 |
| 250 let targetChecks = { | 250 let targetChecks = { |
| 251 extension: v => v == addonName, | 251 extension: v => v === addonName, |
| 252 extensionMinVersion: | 252 extensionMinVersion: |
| 253 v => compareVersion(addonVersion, v) >= 0, | 253 v => compareVersion(addonVersion, v) >= 0, |
| 254 extensionMaxVersion: | 254 extensionMaxVersion: |
| 255 v => compareVersion(addonVersion, v) <= 0, | 255 v => compareVersion(addonVersion, v) <= 0, |
| 256 application: v => v == application, | 256 application: v => v === application, |
| 257 applicationMinVersion: | 257 applicationMinVersion: |
| 258 v => compareVersion(applicationVersion, v) >= 0, | 258 v => compareVersion(applicationVersion, v) >= 0, |
| 259 applicationMaxVersion: | 259 applicationMaxVersion: |
| 260 v => compareVersion(applicationVersion, v) <= 0, | 260 v => compareVersion(applicationVersion, v) <= 0, |
| 261 platform: v => v == platform, | 261 platform: v => v === platform, |
| 262 platformMinVersion: | 262 platformMinVersion: |
| 263 v => compareVersion(platformVersion, v) >= 0, | 263 v => compareVersion(platformVersion, v) >= 0, |
| 264 platformMaxVersion: | 264 platformMaxVersion: |
| 265 v => compareVersion(platformVersion, v) <= 0, | 265 v => compareVersion(platformVersion, v) <= 0, |
| 266 blockedTotalMin: v => Prefs.show_statsinpopup && | 266 blockedTotalMin: v => Prefs.show_statsinpopup && |
| 267 Prefs.blocked_total >= v, | 267 Prefs.blocked_total >= v, |
| 268 blockedTotalMax: v => Prefs.show_statsinpopup && | 268 blockedTotalMax: v => Prefs.show_statsinpopup && |
| 269 Prefs.blocked_total <= v, | 269 Prefs.blocked_total <= v, |
| 270 locales: v => v.includes(Utils.appLocale) | 270 locales: v => v.includes(Utils.appLocale) |
| 271 }; | 271 }; |
| 272 | 272 |
| 273 let notificationToShow = null; | 273 let notificationToShow = null; |
| 274 for (let notification of notifications) | 274 for (let notification of notifications) |
| 275 { | 275 { |
| 276 if (typeof notification.type === "undefined" || | 276 if (typeof notification.type === "undefined" || |
| 277 notification.type !== "critical") | 277 notification.type !== "critical") |
| 278 { | 278 { |
| 279 let shown; | 279 let shown; |
| 280 if (typeof Prefs.notificationdata.shown == "object") | 280 if (typeof Prefs.notificationdata.shown === "object") |
| 281 shown = Prefs.notificationdata.shown[notification.id]; | 281 shown = Prefs.notificationdata.shown[notification.id]; |
| 282 | 282 |
| 283 if (typeof shown != "undefined") | 283 if (typeof shown !== "undefined") |
| 284 { | 284 { |
| 285 if (typeof notification.interval == "number") | 285 if (typeof notification.interval === "number") |
| 286 { | 286 { |
| 287 if (shown + notification.interval > Date.now()) | 287 if (shown + notification.interval > Date.now()) |
| 288 continue; | 288 continue; |
| 289 } | 289 } |
| 290 else if (shown) | 290 else if (shown) |
| 291 continue; | 291 continue; |
| 292 } | 292 } |
| 293 | 293 |
| 294 if (notification.type !== "relentless" && | 294 if (notification.type !== "relentless" && |
| 295 Prefs.notifications_ignoredcategories.indexOf("*") != -1) | 295 Prefs.notifications_ignoredcategories.indexOf("*") !== -1) |
| 296 { | 296 { |
| 297 continue; | 297 continue; |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 if (typeof url === "string" || notification.urlFilters instanceof Array) | 301 if (typeof url === "string" || notification.urlFilters instanceof Array) |
| 302 { | 302 { |
| 303 if (Prefs.enabled && typeof url === "string" && | 303 if (Prefs.enabled && typeof url === "string" && |
| 304 notification.urlFilters instanceof Array) | 304 notification.urlFilters instanceof Array) |
| 305 { | 305 { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 let data = Prefs.notificationdata; | 386 let data = Prefs.notificationdata; |
| 387 | 387 |
| 388 if (data.shown instanceof Array) | 388 if (data.shown instanceof Array) |
| 389 { | 389 { |
| 390 let newShown = {}; | 390 let newShown = {}; |
| 391 for (let oldId of data.shown) | 391 for (let oldId of data.shown) |
| 392 newShown[oldId] = now; | 392 newShown[oldId] = now; |
| 393 data.shown = newShown; | 393 data.shown = newShown; |
| 394 } | 394 } |
| 395 | 395 |
| 396 if (typeof data.shown != "object") | 396 if (typeof data.shown !== "object") |
| 397 data.shown = {}; | 397 data.shown = {}; |
| 398 | 398 |
| 399 data.shown[id] = now; | 399 data.shown[id] = now; |
| 400 | 400 |
| 401 saveNotificationData(); | 401 saveNotificationData(); |
| 402 }, | 402 }, |
| 403 | 403 |
| 404 /** | 404 /** |
| 405 * Localizes the texts of the supplied notification. | 405 * Localizes the texts of the supplied notification. |
| 406 * @param {Object} notification notification to translate | 406 * @param {Object} notification notification to translate |
| 407 * @return {Object} the translated texts | 407 * @return {Object} the translated texts |
| 408 */ | 408 */ |
| 409 getLocalizedTexts(notification) | 409 getLocalizedTexts(notification) |
| 410 { | 410 { |
| 411 let textKeys = ["title", "message"]; | 411 let textKeys = ["title", "message"]; |
| 412 let localizedTexts = {}; | 412 let localizedTexts = {}; |
| 413 for (let key of textKeys) | 413 for (let key of textKeys) |
| 414 { | 414 { |
| 415 if (key in notification) | 415 if (key in notification) |
| 416 { | 416 { |
| 417 if (typeof notification[key] == "string") | 417 if (typeof notification[key] === "string") |
| 418 localizedTexts[key] = notification[key]; | 418 localizedTexts[key] = notification[key]; |
| 419 else | 419 else |
| 420 localizedTexts[key] = localize(notification[key], Utils.appLocale); | 420 localizedTexts[key] = localize(notification[key], Utils.appLocale); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 return localizedTexts; | 423 return localizedTexts; |
| 424 }, | 424 }, |
| 425 | 425 |
| 426 /** | 426 /** |
| 427 * Adds a local notification. | 427 * Adds a local notification. |
| 428 * @param {Object} notification notification to add | 428 * @param {Object} notification notification to add |
| 429 */ | 429 */ |
| 430 addNotification(notification) | 430 addNotification(notification) |
| 431 { | 431 { |
| 432 if (localData.indexOf(notification) == -1) | 432 if (localData.indexOf(notification) === -1) |
| 433 localData.push(notification); | 433 localData.push(notification); |
| 434 }, | 434 }, |
| 435 | 435 |
| 436 /** | 436 /** |
| 437 * Removes an existing local notification. | 437 * Removes an existing local notification. |
| 438 * @param {Object} notification notification to remove | 438 * @param {Object} notification notification to remove |
| 439 */ | 439 */ |
| 440 removeNotification(notification) | 440 removeNotification(notification) |
| 441 { | 441 { |
| 442 let index = localData.indexOf(notification); | 442 let index = localData.indexOf(notification); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 496 |
| 497 /** | 497 /** |
| 498 * Toggles whether notifications of a specific category should be ignored | 498 * Toggles whether notifications of a specific category should be ignored |
| 499 * @param {string} category notification category identifier | 499 * @param {string} category notification category identifier |
| 500 * @param {boolean} [forceValue] force specified value | 500 * @param {boolean} [forceValue] force specified value |
| 501 */ | 501 */ |
| 502 toggleIgnoreCategory(category, forceValue) | 502 toggleIgnoreCategory(category, forceValue) |
| 503 { | 503 { |
| 504 let categories = Prefs.notifications_ignoredcategories; | 504 let categories = Prefs.notifications_ignoredcategories; |
| 505 let index = categories.indexOf(category); | 505 let index = categories.indexOf(category); |
| 506 if (index == -1 && forceValue !== false) | 506 if (index === -1 && forceValue !== false) |
| 507 { | 507 { |
| 508 categories.push(category); | 508 categories.push(category); |
| 509 Prefs.notifications_showui = true; | 509 Prefs.notifications_showui = true; |
| 510 } | 510 } |
| 511 else if (index != -1 && forceValue !== true) | 511 else if (index !== -1 && forceValue !== true) |
| 512 categories.splice(index, 1); | 512 categories.splice(index, 1); |
| 513 | 513 |
| 514 // HACK: JSON values aren't saved unless they are assigned a | 514 // HACK: JSON values aren't saved unless they are assigned a |
| 515 // different object. | 515 // different object. |
| 516 Prefs.notifications_ignoredcategories = | 516 Prefs.notifications_ignoredcategories = |
| 517 JSON.parse(JSON.stringify(categories)); | 517 JSON.parse(JSON.stringify(categories)); |
| 518 } | 518 } |
| 519 }; | 519 }; |
| 520 Notification.init(); | 520 Notification.init(); |
| OLD | NEW |