- Added desktop notifications support (Chrome only)

- Options page prepared for embedding (not implemented yet)
This commit is contained in:
Alexey Skobkin 2014-04-05 03:57:26 +04:00
parent 2e89ca8966
commit 09583da801
5 changed files with 44 additions and 4 deletions

View file

@ -3,4 +3,17 @@ chrome.extension.onMessage.addListener(function(message, sender) {
var tab = sender.tab; var tab = sender.tab;
chrome.pageAction.show(tab.id); 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 */}
));
}
}); });

View file

@ -14,7 +14,7 @@ var ppOptions = [
// WebSocket // WebSocket
'option_ws', 'option_ws',
// Comments // Comments
'option_ws_comments', 'option_ws_comments_color_fadeout', 'option_ws_comments', 'option_ws_comments_color_fadeout', 'option_ws_comments_notifications',
// Feeds // Feeds
'option_ws_feeds', 'option_ws_feeds_subscriptions', 'option_ws_feeds_blogs' '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'); var option_ws_comments = document.getElementById('option-ws-comments');
// Fade out highlight comments // Fade out highlight comments
var option_ws_comments_color_fadeout = document.getElementById('option-ws-comments-color-fadeout'); 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 // Feeds
var option_ws_feeds = document.getElementById('option-ws-feeds'); var option_ws_feeds = document.getElementById('option-ws-feeds');
// Subscriptions // Subscriptions
@ -68,6 +70,7 @@ function pp_save_options() {
'option_ws': option_ws.checked, 'option_ws': option_ws.checked,
'option_ws_comments': option_ws_comments.checked, 'option_ws_comments': option_ws_comments.checked,
'option_ws_comments_color_fadeout': option_ws_comments_color_fadeout.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': option_ws_feeds.checked,
'option_ws_feeds_subscriptions': option_ws_feeds_subscriptions.checked, 'option_ws_feeds_subscriptions': option_ws_feeds_subscriptions.checked,
'option_ws_feeds_blogs': option_ws_feeds_blogs.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) { if (options.option_ws_comments_color_fadeout == true) {
document.getElementById('option-ws-comments-color-fadeout').checked = 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 // Feeds
if (options.option_ws_feeds == true) { if (options.option_ws_feeds == true) {
document.getElementById('option-ws-feeds').checked = true; document.getElementById('option-ws-feeds').checked = true;

View file

@ -264,6 +264,18 @@ $(document).ready(function() {
$commentTemplate.children('.pp-highlight').fadeOut(20000); $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(); console.groupEnd();
}); });
@ -308,7 +320,6 @@ $(document).ready(function() {
; ;
}; };
} }
}); });
// Showing page action // Showing page action

View file

@ -51,6 +51,7 @@
"permissions": [ "permissions": [
"http://*.point.im/*", "http://*.point.im/*",
"https://*.point.im/*", "https://*.point.im/*",
"storage" "storage",
"notifications"
] ]
} }

View file

@ -39,7 +39,7 @@
</div> </div>
<div class="option"> <div class="option">
<input type="checkbox" id="option-embedding"><label for="option-embedding">Enable embedding</label> <input type="checkbox" id="option-embedding" disabled><label for="option-embedding">Enable embedding</label>
<div class="option"> <div class="option">
<input type="checkbox" id="option-embedding-soundcloud"><label for="option-embedding-soundcloud">Soundcloud</label> <input type="checkbox" id="option-embedding-soundcloud"><label for="option-embedding-soundcloud">Soundcloud</label>
@ -79,6 +79,10 @@
<div class="option"> <div class="option">
<input type="checkbox" id="option-ws-comments-color-fadeout"><label for="option-ws-comments-color-fadeout">Fade out highlight in 20 sec</label> <input type="checkbox" id="option-ws-comments-color-fadeout"><label for="option-ws-comments-color-fadeout">Fade out highlight in 20 sec</label>
</div> </div>
<div class="option">
<input type="checkbox" id="option-ws-comments-notifications"><label for="option-ws-comments-notifications">Show desktop notifications (Chrome only)</label>
</div>
</div> </div>
<div class="option"> <div class="option">