Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -292,16 +292,88 @@ |
iconAnimation.update(activeNotification.severity); |
} |
+function openNotificationLinks() |
+{ |
+ if (activeNotification.links) |
+ { |
+ activeNotification.links.forEach(function(link) |
+ { |
+ ext.windows.getLastFocused(function(win) |
+ { |
+ win.openTab(Utils.getDocLink(link)); |
+ }); |
+ }); |
+ } |
+ prepareNotificationIconAndPopup(); |
+} |
+ |
+function notificationButtonClick(id, index) |
+{ |
+ if (activeNotification.links && activeNotification.links[index]) |
+ { |
+ ext.windows.getLastFocused(function(win) |
+ { |
+ win.openTab(Utils.getDocLink(activeNotification.links[index])); |
+ }); |
+ } |
+ prepareNotificationIconAndPopup(); |
+} |
+ |
function showNotification(notification) |
{ |
activeNotification = notification; |
- |
- if (activeNotification.severity === "critical" |
- && typeof webkitNotifications !== "undefined") |
+ if (activeNotification.severity === "critical") |
{ |
- var notification = webkitNotifications.createHTMLNotification("notification.html"); |
- notification.show(); |
- notification.addEventListener("close", prepareNotificationIconAndPopup); |
+ var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
+ if (hasWebkitNotifications && "createHTMLNotification" in webkitNotifications) |
+ { |
+ var notification = webkitNotifications.createHTMLNotification("notification.html"); |
+ notification.show(); |
+ notification.addEventListener("close", prepareNotificationIconAndPopup, false); |
+ return; |
+ } |
+ |
+ var texts = Notification.getLocalizedTexts(notification); |
+ var title = texts.title || ""; |
+ var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
+ var iconUrl = ext.getURL("icons/abp-128.png"); |
+ if ("browserNotifications" in ext) |
+ { |
+ var opts = { |
+ type: "basic", |
+ title: title, |
+ message: message, |
+ iconUrl: iconUrl, |
+ buttons: [] |
+ }; |
+ var regex = /<a>(.*?)<\/a>/g; |
+ var plainMessage = texts.message || ""; |
+ while (match = regex.exec(plainMessage)) |
Felix Dahlke
2014/02/21 13:53:40
As I said in my other comment, feel free to stick
Thomas Greiner
2014/02/21 14:35:53
Avoid making "match" a global variable by prependi
Thomas Greiner
2014/02/21 14:35:53
@Felix Calling it once is not enough. regex.exec r
Felix Dahlke
2014/02/21 15:01:48
Oh yeah, we have multiple links of course, silly m
saroyanm
2014/02/21 15:03:25
Thomas was faster :)
Actually I'm not sure but is
Thomas Greiner
2014/02/21 15:18:43
This is of course an option but I prefer the curre
saroyanm
2014/02/21 15:29:00
Already applied. The case is I didn't prepend beca
|
+ opts.buttons.push({title: match[1]}); |
+ |
+ var notification = ext.browserNotifications; |
+ notification.create("", opts, function() {}); |
+ notification.onClosed.addListener(prepareNotificationIconAndPopup); |
+ notification.onButtonClicked.addListener(notificationButtonClick); |
+ } |
+ else if (hasWebkitNotifications && "createNotification" in webkitNotifications) |
+ { |
+ var notification = webkitNotifications.createNotification(iconUrl, title, message); |
+ notification.show(); |
+ notification.addEventListener("close", prepareNotificationIconAndPopup, false); |
+ notification.addEventListener("click", openNotificationLinks, false); |
+ } |
+ else |
+ { |
+ var message = title + "\n" + message; |
+ if (activeNotification.links && activeNotification.links.length > 0) |
+ { |
+ message += "\n\nClick 'OK' to open the links in this notification."; |
Felix Dahlke
2014/02/21 13:53:40
This needs to be translated :) You can just add th
saroyanm
2014/02/21 15:03:25
Thanks for pointing this.
|
+ } |
+ var notification = confirm(message); |
+ if (notification == true) |
+ openNotificationLinks(); |
+ } |
} |
else |
prepareNotificationIconAndPopup(); |