| 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-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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 let texts = NotificationStorage.getLocalizedTexts(notification); | 186 let texts = NotificationStorage.getLocalizedTexts(notification); |
| 187 let title = texts.title || ""; | 187 let title = texts.title || ""; |
| 188 let message = (texts.message || "").replace(/<\/?(a|strong)>/g, ""); | 188 let message = (texts.message || "").replace(/<\/?(a|strong)>/g, ""); |
| 189 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 189 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
| 190 let linkCount = (activeNotification.links || []).length; | 190 let linkCount = (activeNotification.links || []).length; |
| 191 | 191 |
| 192 if ("notifications" in chrome) | 192 if ("notifications" in chrome) |
| 193 { | 193 { |
| 194 activeButtons = getNotificationButtons(activeNotification.type, | 194 activeButtons = getNotificationButtons(activeNotification.type, |
| 195 texts.message); | 195 texts.message); |
| 196 chrome.notifications.create("", { | 196 let options = { |
| 197 type: "basic", | 197 type: "basic", |
| 198 title, | 198 title, |
| 199 iconUrl, | 199 iconUrl, |
| 200 message, | 200 message, |
| 201 buttons: activeButtons.map(button => ({title: button.title})), | 201 buttons: activeButtons.map(button => ({title: button.title})), |
| 202 // We use the highest priority to prevent the notification | 202 // We use the highest priority to prevent the notification |
| 203 // from closing automatically. | 203 // from closing automatically. |
| 204 priority: 2 | 204 priority: 2 |
| 205 }; | |
| 206 chrome.notifications.create("", options, () => | |
| 207 { | |
| 208 if (chrome.runtime.lastError && chrome.runtime.lastError.message === ` | |
| 209 Adding buttons to notifications is not supported.`) | |
|
Sebastian Noack
2017/10/21 21:04:28
I would skip the check for the error message. If i
Jon Sonesen
2017/10/30 22:41:41
Done.
| |
| 210 { | |
| 211 delete options.buttons; | |
|
Jon Sonesen
2017/10/19 21:59:17
perhaps it is better to move this down or put all
Sebastian Noack
2017/10/21 21:04:28
Yeah, I guess this operation makes more sense in t
Jon Sonesen
2017/10/30 22:41:41
Done.
| |
| 212 if (activeNotification.type != "question") | |
| 213 chrome.notifications.create("", options); | |
| 214 } | |
| 205 }); | 215 }); |
| 206 } | 216 } |
| 207 else if ("Notification" in window && activeNotification.type != "question") | 217 else if ("Notification" in window && activeNotification.type != "question") |
| 208 { | 218 { |
| 209 if (linkCount > 0) | 219 if (linkCount > 0) |
| 210 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 220 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
| 211 | 221 |
| 212 let widget = new Notification( | 222 let widget = new Notification( |
| 213 title, | 223 title, |
| 214 { | 224 { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 282 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
| 273 return methods.includes(method); | 283 return methods.includes(method); |
| 274 }; | 284 }; |
| 275 | 285 |
| 276 ext.pages.onLoading.addListener(page => | 286 ext.pages.onLoading.addListener(page => |
| 277 { | 287 { |
| 278 NotificationStorage.showNext(stringifyURL(page.url)); | 288 NotificationStorage.showNext(stringifyURL(page.url)); |
| 279 }); | 289 }); |
| 280 | 290 |
| 281 NotificationStorage.addShowListener(showNotification); | 291 NotificationStorage.addShowListener(showNotification); |
| OLD | NEW |