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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 notificationClosed(); | 56 notificationClosed(); |
57 }; | 57 }; |
58 if (animateIcon) | 58 if (animateIcon) |
59 startIconAnimation(activeNotification.type); | 59 startIconAnimation(activeNotification.type); |
60 } | 60 } |
61 | 61 |
62 function openNotificationLinks() | 62 function openNotificationLinks() |
63 { | 63 { |
64 if (activeNotification.links) | 64 if (activeNotification.links) |
65 { | 65 { |
66 activeNotification.links.forEach(function(link) | 66 for (let link of activeNotification.links) |
Sebastian Noack
2015/09/11 10:58:26
I wonder why we did it that complicated in the fir
Thomas Greiner
2015/09/11 12:51:48
From what I've seen `ext.pages.open` wasn't availa
| |
67 { | 67 ext.pages.open(Utils.getDocLink(link)); |
68 ext.windows.getLastFocused(function(win) | |
69 { | |
70 win.openTab(Utils.getDocLink(link)); | |
71 }); | |
72 }); | |
73 } | 68 } |
74 } | 69 } |
75 | 70 |
76 function notificationButtonClick(buttonIndex) | 71 function notificationButtonClick(buttonIndex) |
77 { | 72 { |
78 if (activeNotification.type == "question") | 73 if (activeNotification.type == "question") |
79 { | 74 { |
80 NotificationStorage.triggerQuestionListeners(activeNotification.id, buttonIn dex == 0); | 75 NotificationStorage.triggerQuestionListeners(activeNotification.id, buttonIn dex == 0); |
81 NotificationStorage.markAsShown(activeNotification.id); | 76 NotificationStorage.markAsShown(activeNotification.id); |
82 activeNotification.onClicked(); | 77 activeNotification.onClicked(); |
83 } | 78 } |
84 else if (activeNotification.links && activeNotification.links[buttonIndex]) | 79 else |
85 { | 80 { |
86 ext.windows.getLastFocused(function(win) | 81 let links = activeNotification.links || []; |
82 if (buttonIndex == 1 || links.length == 0) | |
87 { | 83 { |
88 win.openTab(Utils.getDocLink(activeNotification.links[buttonIndex])); | 84 Prefs.notifications_showui = true; |
89 }); | 85 ext.showOptions(function(page) |
86 { | |
87 page.sendMessage({ | |
88 type: "focus-section", | |
89 section: "notifications" | |
90 }); | |
91 }); | |
92 } | |
93 else if (links.length == 1) | |
94 ext.pages.open(Utils.getDocLink(activeNotification.links[0])); | |
95 else | |
96 openNotificationLinks(); | |
90 } | 97 } |
91 } | 98 } |
92 | 99 |
93 function notificationClosed() | 100 function notificationClosed() |
94 { | 101 { |
95 activeNotification = null; | 102 activeNotification = null; |
96 } | 103 } |
97 | 104 |
98 function imgToBase64(url, callback) | 105 function imgToBase64(url, callback) |
99 { | 106 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 if (activeNotification && activeNotification.id == notification.id) | 147 if (activeNotification && activeNotification.id == notification.id) |
141 return; | 148 return; |
142 | 149 |
143 activeNotification = notification; | 150 activeNotification = notification; |
144 if (shouldDisplay("notification", activeNotification.type)) | 151 if (shouldDisplay("notification", activeNotification.type)) |
145 { | 152 { |
146 let texts = NotificationStorage.getLocalizedTexts(notification); | 153 let texts = NotificationStorage.getLocalizedTexts(notification); |
147 let title = texts.title || ""; | 154 let title = texts.title || ""; |
148 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 155 let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
149 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); | 156 let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
150 let hasLinks = activeNotification.links && activeNotification.links.length > 0; | 157 let linkCount = (activeNotification.links || []).length; |
151 | 158 |
152 if (canUseChromeNotifications) | 159 if (canUseChromeNotifications) |
153 { | 160 { |
154 let opts = { | 161 let opts = { |
155 type: "basic", | 162 type: "basic", |
156 title: title, | 163 title: title, |
157 message: message, | 164 message: message, |
158 buttons: [], | 165 buttons: [], |
159 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 166 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
160 }; | 167 }; |
161 if (activeNotification.type == "question") | 168 if (activeNotification.type == "question") |
162 { | 169 { |
163 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); | 170 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); |
164 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); | 171 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); |
165 } | 172 } |
166 else | 173 else |
167 { | 174 { |
168 let regex = /<a>(.*?)<\/a>/g; | 175 if (linkCount == 1) |
169 let plainMessage = texts.message || ""; | 176 { |
170 let match; | 177 let match = /<a>(.*?)<\/a>/.exec(texts.message || ""); |
Sebastian Noack
2015/09/11 10:58:26
Nit: .exec() simply returns null if you pass null
Thomas Greiner
2015/09/11 12:51:48
Done.
| |
171 while (match = regex.exec(plainMessage)) | 178 if (match) |
172 opts.buttons.push({title: match[1]}); | 179 opts.buttons.push({title: match[1]}); |
180 } | |
181 else if (linkCount > 1) | |
182 opts.buttons.push({title: ext.i18n.getMessage("notification_open_all") }); | |
183 opts.buttons.push({title: ext.i18n.getMessage("notification_configure")} ); | |
173 } | 184 } |
174 | 185 |
175 imgToBase64(iconUrl, function(iconData) | 186 imgToBase64(iconUrl, function(iconData) |
176 { | 187 { |
177 opts["iconUrl"] = iconData; | 188 opts["iconUrl"] = iconData; |
178 chrome.notifications.create("", opts, function() {}); | 189 chrome.notifications.create("", opts, function() {}); |
179 }); | 190 }); |
180 } | 191 } |
181 else if ("Notification" in window && activeNotification.type != "question") | 192 else if ("Notification" in window && activeNotification.type != "question") |
182 { | 193 { |
183 if (hasLinks) | 194 if (linkCount == 0) |
184 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 195 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
185 | 196 |
186 imgToBase64(iconUrl, function(iconData) | 197 imgToBase64(iconUrl, function(iconData) |
187 { | 198 { |
188 let notification = new Notification( | 199 let notification = new Notification( |
189 title, | 200 title, |
190 { | 201 { |
191 lang: Utils.appLocale, | 202 lang: Utils.appLocale, |
192 dir: ext.i18n.getMessage("@@bidi_dir"), | 203 dir: ext.i18n.getMessage("@@bidi_dir"), |
193 body: message, | 204 body: message, |
194 icon: iconData | 205 icon: iconData |
195 } | 206 } |
196 ); | 207 ); |
197 | 208 |
198 notification.addEventListener("click", openNotificationLinks); | 209 notification.addEventListener("click", openNotificationLinks); |
199 notification.addEventListener("close", notificationClosed); | 210 notification.addEventListener("close", notificationClosed); |
200 }); | 211 }); |
201 } | 212 } |
202 else | 213 else |
203 { | 214 { |
204 let message = title + "\n" + message; | 215 let message = title + "\n" + message; |
205 if (hasLinks) | 216 if (linkCount == 0) |
206 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 217 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
207 | 218 |
208 let approved = confirm(message); | 219 let approved = confirm(message); |
209 if (activeNotification.type == "question") | 220 if (activeNotification.type == "question") |
210 notificationButtonClick(approved ? 0 : 1); | 221 notificationButtonClick(approved ? 0 : 1); |
211 else if (approved) | 222 else if (approved) |
212 openNotificationLinks(); | 223 openNotificationLinks(); |
213 } | 224 } |
214 } | 225 } |
215 prepareNotificationIconAndPopup(); | 226 prepareNotificationIconAndPopup(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 * @return {boolean} | 265 * @return {boolean} |
255 */ | 266 */ |
256 exports.shouldDisplay = shouldDisplay; | 267 exports.shouldDisplay = shouldDisplay; |
257 function shouldDisplay(method, notificationType) | 268 function shouldDisplay(method, notificationType) |
258 { | 269 { |
259 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 270 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
260 return methods.indexOf(method) > -1; | 271 return methods.indexOf(method) > -1; |
261 } | 272 } |
262 | 273 |
263 NotificationStorage.addShowListener(showNotification); | 274 NotificationStorage.addShowListener(showNotification); |
OLD | NEW |