mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-12-28 17:24:20 +00:00
Notification click bugfix.
This commit is contained in:
parent
26b5da4e93
commit
dcb1dcf529
|
@ -8,6 +8,23 @@ chrome.storage.sync.get('options_version', function(data) {
|
|||
}
|
||||
});
|
||||
|
||||
// Adding notification click event listener
|
||||
chrome.notifications.onClicked.addListener(function(notificationId) {
|
||||
// Detecting notification type
|
||||
if (notificationId.indexOf('comment_') === 0) {
|
||||
tab_url = 'https://point.im/' + notificationId.replace(/comment_/g, '');
|
||||
} else if (notificationId.indexOf('post_') === 0) {
|
||||
tab_url = 'https://point.im/' + notificationId.replace(/post_/g, '');
|
||||
}
|
||||
console.log('Notification %s clicked! Opening new tab: %s', notificationId, tab_url);
|
||||
|
||||
if (tab_url !== undefined) {
|
||||
chrome.tabs.create({
|
||||
url: tab_url
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Crutches and bikes
|
||||
/**
|
||||
* Inject several JS files
|
||||
|
@ -79,30 +96,6 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
|
|||
return true;
|
||||
break;
|
||||
|
||||
case 'listenNotificationClicks':
|
||||
// Adding notification click event listener
|
||||
chrome.notifications.onClicked.addListener(function(notificationId) {
|
||||
// Detecting notification type
|
||||
if (notificationId.indexOf('comment_') === 0) {
|
||||
tab_url = message.protocol + '//' + 'point.im/' + notificationId.replace(/comment_/g, '');
|
||||
} else if (notificationId.indexOf('post_') === 0) {
|
||||
tab_url = message.protocol + '//' + 'point.im/' + notificationId.replace(/post_/g, '');
|
||||
}
|
||||
console.log('Notification %s clicked! Opening new tab: %s', notificationId, tab_url);
|
||||
|
||||
if (tab_url !== undefined) {
|
||||
chrome.tabs.create({
|
||||
url: tab_url
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
sendResponse(true);
|
||||
|
||||
// Fuck You, Chrome API documentation!
|
||||
return true;
|
||||
break;
|
||||
|
||||
/**
|
||||
* @deprecated since 1.19.1
|
||||
*/
|
||||
|
|
|
@ -381,13 +381,6 @@ $(document).ready(function() {
|
|||
ws = new WebSocket(((location.protocol == 'https:') ? 'wss' : 'ws') + '://point.im/ws');
|
||||
console.log('WebSocket created: %O', ws);
|
||||
|
||||
// @todo: унести в опцию
|
||||
// Adding event listener for notification click
|
||||
chrome.runtime.sendMessage({
|
||||
type: 'listenNotificationClicks',
|
||||
protocol: getProtocol()
|
||||
});
|
||||
|
||||
// Detecting post id if presented
|
||||
var postId = $('#top-post').attr('data-id');
|
||||
console.debug('Current post id detected as #%s', postId);
|
||||
|
@ -477,7 +470,7 @@ $(document).ready(function() {
|
|||
type: 'showNotification',
|
||||
notificationId: 'comment_' + wsMessage.post_id + '#' + wsMessage.comment_id,
|
||||
avatarUrl: getProtocol() + '//point.im/avatar/' + wsMessage.author + '/80',
|
||||
title: '@' + wsMessage.author + ' #' + wsMessage.post_id + '/' + wsMessage.comment_id + '',
|
||||
title: '@' + wsMessage.author + ' #' + wsMessage.post_id + '/' + wsMessage.comment_id,
|
||||
text: wsMessage.text
|
||||
}, function(response) {});
|
||||
}
|
||||
|
@ -493,6 +486,17 @@ $(document).ready(function() {
|
|||
console.groupCollapsed('ws-post #%s', wsMessage.post_id);
|
||||
|
||||
console.debug(wsMessage);
|
||||
|
||||
if (true /*options.is('option_ws_posts_notifications')*/) {
|
||||
console.log('Showing desktop notification');
|
||||
chrome.runtime.sendMessage({
|
||||
type: 'showNotification',
|
||||
notificationId: 'post_' + wsMessage.post_id,
|
||||
avatarUrl: getProtocol() + '//point.im/avatar/' + wsMessage.author + '/80',
|
||||
title: 'Post by @' + wsMessage.author + ' #' + wsMessage.post_id,
|
||||
text: wsMessage.text
|
||||
}, function(response) {});
|
||||
}
|
||||
|
||||
console.groupEnd();
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue