Index: notification.js |
diff --git a/notification.js b/notification.js |
index 18eff540b3dddc0664594f2fce064a2e3f742183..79c2a3a4d67b4606726abe5387fb80ffcd9a4e88 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 */ |
Sebastian Noack
2017/10/08 19:17:22
As I already told Manish on a different review, I'
kzar
2017/10/09 10:33:25
Acknowledged.
|
-const {Utils} = require("utils"); |
-const {Notification} = require("notification"); |
-const {getActiveNotification, shouldDisplay} = require("notificationHelper"); |
+"use strict"; |
function getDocLinks(notification) |
{ |
+ let docLinks = []; |
Manish Jethani
2017/10/08 22:31:34
The variable is unnecessary here.
kzar
2017/10/09 10:33:25
Sure, we could return an empty array if notificati
Manish Jethani
2017/10/09 10:54:12
I must be looking at the wrong diff, because to me
kzar
2017/10/09 15:10:54
Oh yea, you are right sorry. I switched to mapping
|
+ |
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) => |
Manish Jethani
2017/10/08 22:31:34
If you prefer it, you could lose the braces and th
kzar
2017/10/09 10:33:25
Yea I considered that, but I figured it looked nic
Manish Jethani
2017/10/09 10:54:12
Acknowledged.
|
+ { |
+ chrome.runtime.sendMessage({ |
+ type: "app.get", |
+ what: "doclink", |
+ link |
+ }, resolve); |
+ }); |
+ }) |
+ ); |
} |
function insertMessage(element, text, links) |
@@ -53,7 +58,7 @@ function insertMessage(element, text, links) |
insertMessage(element, before, links); |
let newElement = document.createElement(tagName); |
- if (tagName === "a" && links && links.length) |
+ if (tagName == "a" && links && links.length) |
newElement.href = links.shift(); |
insertMessage(newElement, value, links); |
element.appendChild(newElement); |
@@ -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") |
+ 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"); |
Manish Jethani
2017/10/08 22:31:34
The "prefs.toggle" implementation in messageRespon
Manish Jethani
2017/10/08 22:40:59
Since we're adding "notifications.get", we could a
kzar
2017/10/09 10:33:25
Well my understanding was the option would be togg
Manish Jethani
2017/10/09 10:54:12
The reason the original code was passing true as t
Manish Jethani
2017/10/09 11:53:52
Looking at this code in adblockpluscore lib/notifi
kzar
2017/10/09 15:10:54
Done.
|
+ |
+ notificationElement.hidden = true; |
+ notification.onClicked(); |
+ } |
+ }, true); |
+ }); |
}, false); |