mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-11-23 18:56:04 +00:00
- Added desktop notifications support (Chrome only)
- Options page prepared for embedding (not implemented yet)
This commit is contained in:
parent
2e89ca8966
commit
09583da801
|
@ -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 */}
|
||||
));
|
||||
}
|
||||
});
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
"permissions": [
|
||||
"http://*.point.im/*",
|
||||
"https://*.point.im/*",
|
||||
"storage"
|
||||
"storage",
|
||||
"notifications"
|
||||
]
|
||||
}
|
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
|
||||
<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">
|
||||
<input type="checkbox" id="option-embedding-soundcloud"><label for="option-embedding-soundcloud">Soundcloud</label>
|
||||
|
@ -79,6 +79,10 @@
|
|||
<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>
|
||||
</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 class="option">
|
||||
|
|
Loading…
Reference in a new issue