mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-11-23 18:56:04 +00:00
Merged skobkin/chrome_point_plus into master
This commit is contained in:
commit
5590f32163
|
@ -1,6 +1,6 @@
|
||||||
The MIT License (MIT)
|
The MIT License (MIT), reference http://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
||||||
Copyright (c) 2014 Alexey Skobkin
|
Copyright (c) 2014 Alexey Skobkin <skobkin-ru@ya.ru>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
|
@ -10,16 +10,38 @@ chrome.extension.onMessage.addListener(function(message, sender) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'showNotification':
|
case 'showNotification':
|
||||||
console.log(chrome.notifications.create(
|
chrome.notifications.create(
|
||||||
message.notificationId, {
|
message.notificationId, {
|
||||||
type: 'basic',
|
type: 'basic',
|
||||||
iconUrl: message.avatarUrl,
|
iconUrl: message.avatarUrl,
|
||||||
title: message.title,
|
title: message.title,
|
||||||
message: message.text,
|
message: message.text,
|
||||||
priority: 0
|
priority: 0,
|
||||||
|
isClickable: true
|
||||||
},
|
},
|
||||||
function() { /* Error checking goes here */}
|
function() { /* Error checking goes here */}
|
||||||
));
|
);
|
||||||
|
|
||||||
|
console.log('Showing notification %s', message.notificationId);
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'injectJSFile':
|
case 'injectJSFile':
|
||||||
|
|
|
@ -287,6 +287,13 @@ $(document).ready(function() {
|
||||||
// SSL or plain
|
// SSL or plain
|
||||||
ws = new WebSocket(((location.protocol == 'https:') ? 'wss' : 'ws') + '://point.im/ws');
|
ws = new WebSocket(((location.protocol == 'https:') ? 'wss' : 'ws') + '://point.im/ws');
|
||||||
console.log('WebSocket created: %O', ws);
|
console.log('WebSocket created: %O', ws);
|
||||||
|
|
||||||
|
// @todo: унести в опцию
|
||||||
|
// Adding event listener for notification click
|
||||||
|
chrome.extension.sendMessage({
|
||||||
|
type: 'listenNotificationClicks',
|
||||||
|
protocol: getProtocol()
|
||||||
|
});
|
||||||
|
|
||||||
// Detecting post id if presented
|
// Detecting post id if presented
|
||||||
var postId = $('#top-post').attr('data-id');
|
var postId = $('#top-post').attr('data-id');
|
||||||
|
@ -347,6 +354,7 @@ $(document).ready(function() {
|
||||||
'data-to-comment-id': (wsMessage.to_comment_id != null) ? wsMessage.to_comment_id : ''
|
'data-to-comment-id': (wsMessage.to_comment_id != null) ? wsMessage.to_comment_id : ''
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// @todo: Вынести в отдельную функцию
|
||||||
// Loading HTML template
|
// Loading HTML template
|
||||||
$commentTemplate.load(chrome.extension.getURL('includes/comment.html'), function() {
|
$commentTemplate.load(chrome.extension.getURL('includes/comment.html'), function() {
|
||||||
// Load complete
|
// Load complete
|
||||||
|
@ -354,7 +362,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Date and time of comment
|
// Date and time of comment
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
|
|
||||||
|
// @todo: унести наверх
|
||||||
// Data for template
|
// Data for template
|
||||||
var userLink = '//' + wsMessage.author + '.point.im/';
|
var userLink = '//' + wsMessage.author + '.point.im/';
|
||||||
var postAuthorLink = $('#top-post .info a').attr('href');
|
var postAuthorLink = $('#top-post .info a').attr('href');
|
||||||
|
@ -362,7 +371,7 @@ $(document).ready(function() {
|
||||||
var userAvatar = '//point.im/avatar/' + wsMessage.author;
|
var userAvatar = '//point.im/avatar/' + wsMessage.author;
|
||||||
var commentLink = '//point.im/' + wsMessage.post_id + '#' + wsMessage.comment_id;
|
var commentLink = '//point.im/' + wsMessage.post_id + '#' + wsMessage.comment_id;
|
||||||
var csRfToken = $('.reply-form input[name="csrf_token"').val();
|
var csRfToken = $('.reply-form input[name="csrf_token"').val();
|
||||||
|
|
||||||
// Filling template
|
// Filling template
|
||||||
console.info('Changing data in the comment element');
|
console.info('Changing data in the comment element');
|
||||||
// Date and time
|
// Date and time
|
||||||
|
@ -439,9 +448,9 @@ $(document).ready(function() {
|
||||||
console.log('Showing desktop notification');
|
console.log('Showing desktop notification');
|
||||||
chrome.extension.sendMessage({
|
chrome.extension.sendMessage({
|
||||||
type: 'showNotification',
|
type: 'showNotification',
|
||||||
notificationId: wsMessage.post_id + '_' + wsMessage.comment_id,
|
notificationId: 'comment_' + wsMessage.post_id + '#' + wsMessage.comment_id,
|
||||||
avatarUrl: ((location.protocol == 'http:') ? 'http:' : 'https:') + userAvatar + '/80',
|
avatarUrl: getProtocol() + userAvatar + '/80',
|
||||||
title: '@' + wsMessage.author + ' → #' + wsMessage.post_id + '(/' + wsMessage.comment_id + ')',
|
title: '@' + wsMessage.author + ' #' + wsMessage.post_id + '(/' + wsMessage.comment_id + ')',
|
||||||
text: wsMessage.text
|
text: wsMessage.text
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -524,6 +533,10 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getProtocol() {
|
||||||
|
return ((location.protocol == 'http:') ? 'http:' : 'https:')
|
||||||
|
}
|
||||||
|
|
||||||
function escapeHtml(text) {
|
function escapeHtml(text) {
|
||||||
return text
|
return text
|
||||||
.replace(/&/g, "&")
|
.replace(/&/g, "&")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Point+",
|
"name": "Point+",
|
||||||
"version": "1.16.0",
|
"version": "1.17.0",
|
||||||
"default_locale": "ru",
|
"default_locale": "ru",
|
||||||
"author": "__MSG_ext_author__",
|
"author": "__MSG_ext_author__",
|
||||||
"homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus",
|
"homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus",
|
||||||
|
|
Loading…
Reference in a new issue