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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 var backgroundPage = ext.backgroundPage.getWindow(); | 18 "use strict"; |
19 var require = backgroundPage.require; | |
20 | 19 |
21 var Utils = require("utils").Utils; | 20 let backgroundPage = ext.backgroundPage.getWindow(); |
22 var Notification = require("notification").Notification; | 21 let require = backgroundPage.require; |
23 var notificationHelper = require("notificationHelper"); | 22 |
24 var getActiveNotification = notificationHelper.getActiveNotification; | 23 let Utils = require("utils").Utils; |
Sebastian Noack
2017/01/16 15:35:56
I suppose we could better use destructuring here n
kzar
2017/01/17 07:42:49
Done.
| |
25 var shouldDisplayNotification = notificationHelper.shouldDisplay; | 24 let Notification = require("notification").Notification; |
25 let notificationHelper = require("notificationHelper"); | |
26 let getActiveNotification = notificationHelper.getActiveNotification; | |
27 let shouldDisplayNotification = notificationHelper.shouldDisplay; | |
26 | 28 |
27 function getDocLinks(notification) | 29 function getDocLinks(notification) |
28 { | 30 { |
29 if (!notification.links) | 31 if (!notification.links) |
30 return []; | 32 return []; |
31 | 33 |
32 var docLinks = []; | 34 let docLinks = []; |
33 notification.links.forEach(function(link) | 35 notification.links.forEach(link => |
34 { | 36 { |
35 docLinks.push(Utils.getDocLink(link)); | 37 docLinks.push(Utils.getDocLink(link)); |
36 }); | 38 }); |
37 return docLinks; | 39 return docLinks; |
38 } | 40 } |
39 | 41 |
40 function insertMessage(element, text, links) | 42 function insertMessage(element, text, links) |
41 { | 43 { |
42 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text); | 44 let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text); |
43 if (!match) | 45 if (!match) |
44 { | 46 { |
45 element.appendChild(document.createTextNode(text)); | 47 element.appendChild(document.createTextNode(text)); |
46 return; | 48 return; |
47 } | 49 } |
48 | 50 |
49 var before = match[1]; | 51 let before = match[1]; |
50 var tagName = match[2]; | 52 let tagName = match[2]; |
51 var value = match[3]; | 53 let value = match[3]; |
52 var after = match[4]; | 54 let after = match[4]; |
53 | 55 |
54 insertMessage(element, before, links); | 56 insertMessage(element, before, links); |
55 | 57 |
56 var newElement = document.createElement(tagName); | 58 let newElement = document.createElement(tagName); |
57 if (tagName === "a" && links && links.length) | 59 if (tagName === "a" && links && links.length) |
58 newElement.href = links.shift(); | 60 newElement.href = links.shift(); |
59 insertMessage(newElement, value, links); | 61 insertMessage(newElement, value, links); |
60 element.appendChild(newElement); | 62 element.appendChild(newElement); |
61 | 63 |
62 insertMessage(element, after, links); | 64 insertMessage(element, after, links); |
63 } | 65 } |
64 | 66 |
65 window.addEventListener("load", function() | 67 window.addEventListener("load", () => |
66 { | 68 { |
67 var notification = getActiveNotification(); | 69 let notification = getActiveNotification(); |
68 if (!notification || !shouldDisplayNotification("popup", notification.type)) | 70 if (!notification || !shouldDisplayNotification("popup", notification.type)) |
69 return; | 71 return; |
70 | 72 |
71 var texts = Notification.getLocalizedTexts(notification); | 73 let texts = Notification.getLocalizedTexts(notification); |
72 var titleElement = document.getElementById("notification-title"); | 74 let titleElement = document.getElementById("notification-title"); |
73 titleElement.textContent = texts.title; | 75 titleElement.textContent = texts.title; |
74 | 76 |
75 var docLinks = getDocLinks(notification); | 77 let docLinks = getDocLinks(notification); |
76 var messageElement = document.getElementById("notification-message"); | 78 let messageElement = document.getElementById("notification-message"); |
77 insertMessage(messageElement, texts.message, docLinks); | 79 insertMessage(messageElement, texts.message, docLinks); |
78 | 80 |
79 messageElement.addEventListener("click", function(event) | 81 messageElement.addEventListener("click", event => |
80 { | 82 { |
81 var link = event.target; | 83 let link = event.target; |
82 while (link && link !== messageElement && link.localName !== "a") | 84 while (link && link !== messageElement && link.localName !== "a") |
83 link = link.parentNode; | 85 link = link.parentNode; |
84 if (!link) | 86 if (!link) |
85 return; | 87 return; |
86 event.preventDefault(); | 88 event.preventDefault(); |
87 event.stopPropagation(); | 89 event.stopPropagation(); |
88 ext.pages.open(link.href); | 90 ext.pages.open(link.href); |
89 }); | 91 }); |
90 | 92 |
91 var notificationElement = document.getElementById("notification"); | 93 let notificationElement = document.getElementById("notification"); |
92 notificationElement.className = notification.type; | 94 notificationElement.className = notification.type; |
93 notificationElement.hidden = false; | 95 notificationElement.hidden = false; |
94 notificationElement.addEventListener("click", function(event) | 96 notificationElement.addEventListener("click", event => |
95 { | 97 { |
96 switch (event.target.id) | 98 switch (event.target.id) |
97 { | 99 { |
98 case "notification-close": | 100 case "notification-close": |
99 notificationElement.classList.add("closing"); | 101 notificationElement.classList.add("closing"); |
100 break; | 102 break; |
101 case "notification-optout": | 103 case "notification-optout": |
102 Notification.toggleIgnoreCategory("*", true); | 104 Notification.toggleIgnoreCategory("*", true); |
103 case "notification-hide": | 105 case "notification-hide": |
104 notificationElement.hidden = true; | 106 notificationElement.hidden = true; |
105 notification.onClicked(); | 107 notification.onClicked(); |
106 break; | 108 break; |
107 } | 109 } |
108 }, true); | 110 }, true); |
109 }, false); | 111 }, false); |
OLD | NEW |