Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /* global togglePref */ | 18 /* global setPref */ |
19 | 19 |
20 "use strict"; | 20 "use strict"; |
21 | 21 |
22 function getDocLinks(notification) | 22 function getDocLinks(notification) |
23 { | 23 { |
24 let docLinks = []; | |
25 | |
26 if (!notification.links) | 24 if (!notification.links) |
27 return Promise.resolve(docLinks); | 25 return Promise.resolve([]); |
28 | 26 |
29 return Promise.all( | 27 return Promise.all( |
30 notification.links.map(link => | 28 notification.links.map(link => |
31 { | 29 { |
32 return new Promise((resolve, reject) => | 30 return new Promise((resolve, reject) => |
33 { | 31 { |
34 chrome.runtime.sendMessage({ | 32 chrome.runtime.sendMessage({ |
35 type: "app.get", | 33 type: "app.get", |
36 what: "doclink", | 34 what: "doclink", |
37 link | 35 link |
(...skipping 13 matching lines...) Expand all Loading... | |
51 } | 49 } |
52 | 50 |
53 let before = match[1]; | 51 let before = match[1]; |
54 let tagName = match[2]; | 52 let tagName = match[2]; |
55 let value = match[3]; | 53 let value = match[3]; |
56 let after = match[4]; | 54 let after = match[4]; |
57 | 55 |
58 insertMessage(element, before, links); | 56 insertMessage(element, before, links); |
59 | 57 |
60 let newElement = document.createElement(tagName); | 58 let newElement = document.createElement(tagName); |
61 if (tagName === "a" && links && links.length) | 59 if (tagName == "a" && links && links.length) |
62 newElement.href = links.shift(); | 60 newElement.href = links.shift(); |
63 insertMessage(newElement, value, links); | 61 insertMessage(newElement, value, links); |
64 element.appendChild(newElement); | 62 element.appendChild(newElement); |
65 | 63 |
66 insertMessage(element, after, links); | 64 insertMessage(element, after, links); |
67 } | 65 } |
68 | 66 |
69 window.addEventListener("load", () => | 67 window.addEventListener("load", () => |
70 { | 68 { |
71 chrome.runtime.sendMessage({ | 69 chrome.runtime.sendMessage({ |
72 type: "notifications.get", | 70 type: "notifications.get", |
73 displayMethod: "popup" | 71 displayMethod: "popup" |
74 }, notification => | 72 }, notification => |
75 { | 73 { |
76 if (!notification) | 74 if (!notification) |
77 return; | 75 return; |
78 | 76 |
79 let titleElement = document.getElementById("notification-title"); | 77 let titleElement = document.getElementById("notification-title"); |
80 let messageElement = document.getElementById("notification-message"); | 78 let messageElement = document.getElementById("notification-message"); |
81 | 79 |
82 titleElement.textContent = notification.texts.title; | 80 titleElement.textContent = notification.texts.title; |
83 | 81 |
84 getDocLinks(notification).then(docLinks => | 82 getDocLinks(notification).then(docLinks => |
85 { | 83 { |
86 insertMessage(messageElement, notification.texts.message, docLinks); | 84 insertMessage(messageElement, notification.texts.message, docLinks); |
87 | 85 |
88 messageElement.addEventListener("click", event => | 86 messageElement.addEventListener("click", event => |
89 { | 87 { |
90 let link = event.target; | 88 let link = event.target; |
91 while (link && link !== messageElement && link.localName !== "a") | 89 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.
| |
92 link = link.parentNode; | 90 link = link.parentNode; |
93 if (!link) | 91 if (!link) |
94 return; | 92 return; |
95 event.preventDefault(); | 93 event.preventDefault(); |
96 event.stopPropagation(); | 94 event.stopPropagation(); |
97 ext.pages.open(link.href); | 95 chrome.tabs.create({url: link.href}); |
98 }); | 96 }); |
99 }); | 97 }); |
100 | 98 |
101 let notificationElement = document.getElementById("notification"); | 99 let notificationElement = document.getElementById("notification"); |
102 notificationElement.className = notification.type; | 100 notificationElement.className = notification.type; |
103 notificationElement.hidden = false; | 101 notificationElement.hidden = false; |
104 notificationElement.addEventListener("click", event => | 102 notificationElement.addEventListener("click", event => |
105 { | 103 { |
106 if (event.target.id == "notification-close") | 104 if (event.target.id == "notification-close") |
107 notificationElement.classList.add("closing"); | 105 notificationElement.classList.add("closing"); |
108 else if (event.target.id == "notification-optout" || | 106 else if (event.target.id == "notification-optout" || |
109 event.target.id == "notification-hide") | 107 event.target.id == "notification-hide") |
110 { | 108 { |
111 if (event.target.id == "notification-optout") | 109 if (event.target.id == "notification-optout") |
112 togglePref("notifications_ignoredcategories"); | 110 setPref("notifications_ignoredcategories", true); |
113 | 111 |
114 notificationElement.hidden = true; | 112 notificationElement.hidden = true; |
115 notification.onClicked(); | 113 notification.onClicked(); |
116 } | 114 } |
117 }, true); | 115 }, true); |
118 }); | 116 }); |
119 }, false); | 117 }, false); |
LEFT | RIGHT |