Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -292,16 +292,82 @@ |
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 ? texts.title : ""; |
+ var message = texts.message ? texts.message.replace(new RegExp("<(a|\/a)>", 'g'), "") : ""; |
Thomas Greiner
2014/02/18 16:44:25
You can just use the literal version (also don't f
saroyanm
2014/02/18 17:53:48
Done.
|
+ var iconUrl = ext.getURL("icons/abp-128.png"); |
+ if ("notifications" in ext) |
+ { |
+ var opt = { |
+ type: "basic", |
+ title: title, |
+ message: message, |
+ iconUrl: iconUrl, |
+ buttons: [] |
+ }; |
+ var regex = /<a>(.*?)<\/a>/g; |
+ while (regex.test(texts.message ? texts.message : "")) |
Thomas Greiner
2014/02/18 16:44:25
Can you move this outside of the while loop?
saroyanm
2014/02/18 17:53:48
Done.
|
+ opt.buttons.push({title: RegExp.$1}); |
+ |
+ var notification = ext.notifications; |
+ notification.create("", opt, 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 notification = confirm(title + "\n" + message); |
+ if (notification == true) |
+ openNotificationLinks(); |
+ } |
} |
else |
prepareNotificationIconAndPopup(); |