From 09583da8017d207bd70bb6b1d86498b798f132ff Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sat, 5 Apr 2014 03:57:26 +0400 Subject: [PATCH] - Added desktop notifications support (Chrome only) - Options page prepared for embedding (not implemented yet) --- chrome_point_plus/js/background.js | 13 +++++++++++++ chrome_point_plus/js/options.js | 13 ++++++++++++- chrome_point_plus/js/point-plus.js | 13 ++++++++++++- chrome_point_plus/manifest.json | 3 ++- chrome_point_plus/options.html | 6 +++++- 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/chrome_point_plus/js/background.js b/chrome_point_plus/js/background.js index 507bc34..cac6a4d 100644 --- a/chrome_point_plus/js/background.js +++ b/chrome_point_plus/js/background.js @@ -3,4 +3,17 @@ chrome.extension.onMessage.addListener(function(message, sender) { var tab = sender.tab; chrome.pageAction.show(tab.id); } + + if (message && message.type === 'showNotification') { + console.log(chrome.notifications.create( + message.notificationId, { + type: 'basic', + iconUrl: message.avatarUrl, + title: message.title, + message: message.text, + priority: 0 + }, + function() { /* Error checking goes here */} + )); + } }); \ No newline at end of file diff --git a/chrome_point_plus/js/options.js b/chrome_point_plus/js/options.js index 95b4213..6dd6a30 100644 --- a/chrome_point_plus/js/options.js +++ b/chrome_point_plus/js/options.js @@ -14,7 +14,7 @@ var ppOptions = [ // WebSocket 'option_ws', // Comments - 'option_ws_comments', 'option_ws_comments_color_fadeout', + 'option_ws_comments', 'option_ws_comments_color_fadeout', 'option_ws_comments_notifications', // Feeds 'option_ws_feeds', 'option_ws_feeds_subscriptions', 'option_ws_feeds_blogs' ]; @@ -47,6 +47,8 @@ function pp_save_options() { var option_ws_comments = document.getElementById('option-ws-comments'); // Fade out highlight comments var option_ws_comments_color_fadeout = document.getElementById('option-ws-comments-color-fadeout'); + // Comments desktop notifications + var option_ws_comments_notifications = document.getElementById('option-ws-comments-notifications'); // Feeds var option_ws_feeds = document.getElementById('option-ws-feeds'); // Subscriptions @@ -68,6 +70,7 @@ function pp_save_options() { 'option_ws': option_ws.checked, 'option_ws_comments': option_ws_comments.checked, 'option_ws_comments_color_fadeout': option_ws_comments_color_fadeout.checked, + 'option_ws_comments_notifications': option_ws_comments_notifications.checked, 'option_ws_feeds': option_ws_feeds.checked, 'option_ws_feeds_subscriptions': option_ws_feeds_subscriptions.checked, 'option_ws_feeds_blogs': option_ws_feeds_blogs.checked @@ -135,6 +138,14 @@ function pp_restore_options() { if (options.option_ws_comments_color_fadeout == true) { document.getElementById('option-ws-comments-color-fadeout').checked = true; } + // Comments desktop notifications + // Disabling for Opera + if (/OPR/.test(navigator.userAgent)) { + document.getElementById('option-ws-comments-notifications').setAttribute('disabled', 'disabled'); + } + if (options.option_ws_comments_notifications == true) { + document.getElementById('option-ws-comments-notifications').checked = true; + } // Feeds if (options.option_ws_feeds == true) { document.getElementById('option-ws-feeds').checked = true; diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index 7dfcee6..af75953 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -264,6 +264,18 @@ $(document).ready(function() { $commentTemplate.children('.pp-highlight').fadeOut(20000); } + // Desktop notifications + if (options.option_ws_comments_notifications == true) { + console.log('Showing desktop notification'); + chrome.extension.sendMessage({ + type: 'showNotification', + notificationId: wsMessage.post_id + '_' + wsMessage.comment_id, + avatarUrl: ((location.protocol == 'http:') ? 'http:' : 'https:') + userAvatar + '/80', + title: '@' + wsMessage.author + ' commented #' + wsMessage.post_id + '(/' + wsMessage.comment_id + ')', + text: wsMessage.text + }); + } + console.groupEnd(); }); @@ -308,7 +320,6 @@ $(document).ready(function() { ; }; } - }); // Showing page action diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index fa70b4f..0e1caec 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -51,6 +51,7 @@ "permissions": [ "http://*.point.im/*", "https://*.point.im/*", - "storage" + "storage", + "notifications" ] } \ No newline at end of file diff --git a/chrome_point_plus/options.html b/chrome_point_plus/options.html index 06d8e17..3dbb86d 100644 --- a/chrome_point_plus/options.html +++ b/chrome_point_plus/options.html @@ -39,7 +39,7 @@
- +
@@ -79,6 +79,10 @@
+ +
+ +