Index: notification.js |
diff --git a/notification.js b/notification.js |
index 18eff540b3dddc0664594f2fce064a2e3f742183..5b06cbbac310d9114e9b9165e1e4ff10f59ba1be 100644 |
--- a/notification.js |
+++ b/notification.js |
@@ -15,25 +15,30 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
-"use strict"; |
- |
-const {require} = ext.backgroundPage.getWindow(); |
+/* global togglePref */ |
-const {Utils} = require("utils"); |
-const {Notification} = require("notification"); |
-const {getActiveNotification, shouldDisplay} = require("notificationHelper"); |
+"use strict"; |
function getDocLinks(notification) |
{ |
+ let docLinks = []; |
+ |
if (!notification.links) |
- return []; |
+ return Promise.resolve(docLinks); |
- let docLinks = []; |
- notification.links.forEach(link => |
- { |
- docLinks.push(Utils.getDocLink(link)); |
- }); |
- return docLinks; |
+ return Promise.all( |
+ notification.links.map(link => |
+ { |
+ return new Promise((resolve, reject) => |
+ { |
+ chrome.runtime.sendMessage({ |
+ type: "app.get", |
+ what: "doclink", |
+ link |
+ }, resolve); |
+ }); |
+ }) |
+ ); |
} |
function insertMessage(element, text, links) |
@@ -63,45 +68,52 @@ function insertMessage(element, text, links) |
window.addEventListener("load", () => |
{ |
- let notification = getActiveNotification(); |
- if (!notification || !shouldDisplay("popup", notification.type)) |
- return; |
- |
- let texts = Notification.getLocalizedTexts(notification); |
- let titleElement = document.getElementById("notification-title"); |
- titleElement.textContent = texts.title; |
- |
- let docLinks = getDocLinks(notification); |
- let messageElement = document.getElementById("notification-message"); |
- insertMessage(messageElement, texts.message, docLinks); |
- |
- messageElement.addEventListener("click", event => |
+ chrome.runtime.sendMessage({ |
+ type: "notifications.get", |
+ displayMethod: "popup" |
+ }, notification => |
{ |
- let link = event.target; |
- while (link && link !== messageElement && link.localName !== "a") |
- link = link.parentNode; |
- if (!link) |
+ if (!notification) |
return; |
- event.preventDefault(); |
- event.stopPropagation(); |
- ext.pages.open(link.href); |
- }); |
- let notificationElement = document.getElementById("notification"); |
- notificationElement.className = notification.type; |
- notificationElement.hidden = false; |
- notificationElement.addEventListener("click", event => |
- { |
- if (event.target.id == "notification-close") |
- notificationElement.classList.add("closing"); |
- else if (event.target.id == "notification-optout" || |
- event.target.id == "notification-hide") |
- { |
- if (event.target.id == "notification-optout") |
- Notification.toggleIgnoreCategory("*", true); |
+ let titleElement = document.getElementById("notification-title"); |
+ let messageElement = document.getElementById("notification-message"); |
+ |
+ titleElement.textContent = notification.texts.title; |
- notificationElement.hidden = true; |
- notification.onClicked(); |
- } |
- }, true); |
+ getDocLinks(notification).then(docLinks => |
+ { |
+ insertMessage(messageElement, notification.texts.message, docLinks); |
+ |
+ messageElement.addEventListener("click", event => |
+ { |
+ let link = event.target; |
+ while (link && link !== messageElement && link.localName !== "a") |
Sebastian Noack
2017/10/08 01:19:21
Nit: As per the Mozilla coding style guide, which
kzar
2017/10/08 10:13:45
Done.
|
+ link = link.parentNode; |
+ if (!link) |
+ return; |
+ event.preventDefault(); |
+ event.stopPropagation(); |
+ ext.pages.open(link.href); |
+ }); |
+ }); |
+ |
+ let notificationElement = document.getElementById("notification"); |
+ notificationElement.className = notification.type; |
+ notificationElement.hidden = false; |
+ notificationElement.addEventListener("click", event => |
+ { |
+ if (event.target.id == "notification-close") |
+ notificationElement.classList.add("closing"); |
+ else if (event.target.id == "notification-optout" || |
+ event.target.id == "notification-hide") |
+ { |
+ if (event.target.id == "notification-optout") |
+ togglePref("notifications_ignoredcategories"); |
+ |
+ notificationElement.hidden = true; |
+ notification.onClicked(); |
+ } |
+ }, true); |
+ }); |
}, false); |