mirror of
https://bitbucket.org/skobkin/chrome_point_plus.git
synced 2024-11-23 18:56:04 +00:00
Add MessageSender module
This commit is contained in:
parent
49328a4b4a
commit
633410061a
20
chrome_point_plus/js/message-sender.js
Normal file
20
chrome_point_plus/js/message-sender.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
function MessageSender() {}
|
||||||
|
function stub() {}
|
||||||
|
|
||||||
|
MessageSender.prototype.css = function(files, callback) {
|
||||||
|
this.sendMessage({
|
||||||
|
type: 'injectCSSFiles',
|
||||||
|
files: files
|
||||||
|
}, callback || stub);
|
||||||
|
};
|
||||||
|
|
||||||
|
MessageSender.prototype.js = function(files, callback) {
|
||||||
|
this.sendMessage({
|
||||||
|
type: 'executeJSFiles',
|
||||||
|
files: files
|
||||||
|
}, callback || stub);
|
||||||
|
};
|
||||||
|
|
||||||
|
MessageSender.prototype.sendMessage = function() {
|
||||||
|
chrome.runtime.sendMessage.apply(chrome.runtime, arguments);
|
||||||
|
};
|
|
@ -1,19 +1,23 @@
|
||||||
|
var messenger = new MessageSender();
|
||||||
|
|
||||||
// Showing page action
|
// Showing page action
|
||||||
chrome.runtime.sendMessage({
|
messenger.sendMessage({
|
||||||
type: 'showPageAction'
|
type: 'showPageAction'
|
||||||
}, null, function(response) {
|
}, function(response) {
|
||||||
console.debug('showPageAction response: %O', response);
|
console.debug('showPageAction response: %O', response);
|
||||||
});
|
});
|
||||||
|
|
||||||
var ppVersion;
|
messenger.sendMessage({
|
||||||
|
type: 'getManifestVersion'
|
||||||
chrome.runtime.sendMessage(null, {
|
}, function(response) {
|
||||||
type: 'getManifestVersion'
|
$(document).ready(function() {
|
||||||
}, null, function(response) {
|
PointPlus(response.version || 'undefined')
|
||||||
ppVersion = response.version || 'undefined';
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
|
function PointPlus(ppVersion) {
|
||||||
|
|
||||||
// Grouping console log
|
// Grouping console log
|
||||||
console.group('point-plus');
|
console.group('point-plus');
|
||||||
console.info('Point+ %s', ppVersion);
|
console.info('Point+ %s', ppVersion);
|
||||||
|
@ -33,6 +37,7 @@ $(document).ready(function() {
|
||||||
draft_set_save_handler();
|
draft_set_save_handler();
|
||||||
draft_restore();
|
draft_restore();
|
||||||
|
|
||||||
|
|
||||||
// Loading options
|
// Loading options
|
||||||
chrome.storage.sync.get('options', function(sync_data) {
|
chrome.storage.sync.get('options', function(sync_data) {
|
||||||
var options = new OptionsManager(sync_data.options);
|
var options = new OptionsManager(sync_data.options);
|
||||||
|
@ -67,13 +72,10 @@ $(document).ready(function() {
|
||||||
// Soundcloud
|
// Soundcloud
|
||||||
if (options.is('option_embedding_soundcloud')) {
|
if (options.is('option_embedding_soundcloud')) {
|
||||||
// Executing Soundcloud player JS API
|
// Executing Soundcloud player JS API
|
||||||
chrome.runtime.sendMessage({
|
messenger.js({
|
||||||
type: 'executeJSFiles',
|
file: 'vendor/soundcloud/soundcloud.player.api.js',
|
||||||
files: [{
|
runAt: 'document_end'
|
||||||
file: 'vendor/soundcloud/soundcloud.player.api.js',
|
}, function(response) {
|
||||||
runAt: 'document_end'
|
|
||||||
}]
|
|
||||||
}, null, function(response) {
|
|
||||||
console.debug('Soundcloud injection response: %O', response);
|
console.debug('Soundcloud injection response: %O', response);
|
||||||
// If scripts are executed
|
// If scripts are executed
|
||||||
if (response) {
|
if (response) {
|
||||||
|
@ -122,27 +124,25 @@ $(document).ready(function() {
|
||||||
// Injecting Fancybox to the page
|
// Injecting Fancybox to the page
|
||||||
// CSS
|
// CSS
|
||||||
// @todo message response callback processing
|
// @todo message response callback processing
|
||||||
chrome.runtime.sendMessage({
|
messenger.css([
|
||||||
type: 'injectCSSFiles',
|
'vendor/fancybox/source/jquery.fancybox.css',
|
||||||
files: [
|
'css/fancybox/style.css'
|
||||||
'vendor/fancybox/source/jquery.fancybox.css',
|
]);
|
||||||
'css/fancybox/style.css'
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
// JS
|
// JS
|
||||||
chrome.runtime.sendMessage(null, {
|
messenger.js([
|
||||||
type: 'executeJSFiles',
|
{
|
||||||
files: [{
|
|
||||||
file: 'vendor/fancybox/source/jquery.fancybox.pack.js',
|
file: 'vendor/fancybox/source/jquery.fancybox.pack.js',
|
||||||
runAt: 'document_end'
|
runAt: 'document_end'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
// @todo Move to the option_fancybox_videos section
|
// @todo Move to the option_fancybox_videos section
|
||||||
file: 'vendor/fancybox/source/helpers/jquery.fancybox-media.js',
|
file: 'vendor/fancybox/source/helpers/jquery.fancybox-media.js',
|
||||||
runAt: 'document_end'
|
runAt: 'document_end'
|
||||||
}]
|
}
|
||||||
}, null, function(response) {
|
], function(response) {
|
||||||
// If all JS are executed
|
// If all JS are executed
|
||||||
|
|
||||||
console.debug('Fancybox injection response: %O', response);
|
console.debug('Fancybox injection response: %O', response);
|
||||||
if (response) {
|
if (response) {
|
||||||
console.log('Fancybox executed. Processing...');
|
console.log('Fancybox executed. Processing...');
|
||||||
|
@ -281,26 +281,23 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// CSS
|
// CSS
|
||||||
// @todo message response callback processing
|
// @todo message response callback processing
|
||||||
chrome.runtime.sendMessage({
|
messenger.css([
|
||||||
type: 'injectCSSFiles',
|
'vendor/markitup/markitup/skins/markitup/style.css',
|
||||||
files: [
|
'css/markitup/skins/markitup/style.css',
|
||||||
'vendor/markitup/markitup/skins/markitup/style.css',
|
'css/markitup/sets/markdown/style.css'
|
||||||
'css/markitup/skins/markitup/style.css',
|
]);
|
||||||
'css/markitup/sets/markdown/style.css'
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
// JS
|
// JS
|
||||||
chrome.runtime.sendMessage({
|
messenger.js([
|
||||||
type: 'executeJSFiles',
|
{
|
||||||
files: [{
|
|
||||||
file: 'vendor/markitup/markitup/jquery.markitup.js',
|
file: 'vendor/markitup/markitup/jquery.markitup.js',
|
||||||
runAt: 'document_end'
|
runAt: 'document_end'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
file: 'js/markitup/sets/markdown/set.js',
|
file: 'js/markitup/sets/markdown/set.js',
|
||||||
runAt: 'document_end'
|
runAt: 'document_end'
|
||||||
}]
|
}
|
||||||
}, null, function(response) {
|
], function(response) {
|
||||||
console.debug('MarkItUp injection response: %O', response);
|
console.debug('MarkItUp injection response: %O', response);
|
||||||
// If scripts are executed
|
// If scripts are executed
|
||||||
if (response) {
|
if (response) {
|
||||||
|
@ -420,7 +417,7 @@ $(document).ready(function() {
|
||||||
// Desktop notifications
|
// Desktop notifications
|
||||||
if (options.is('option_ws_comments_notifications')) {
|
if (options.is('option_ws_comments_notifications')) {
|
||||||
console.log('Showing desktop notification');
|
console.log('Showing desktop notification');
|
||||||
chrome.runtime.sendMessage({
|
messenger.sendMessage({
|
||||||
type: 'showNotification',
|
type: 'showNotification',
|
||||||
notificationId: 'comment_' + wsMessage.post_id + '#' + wsMessage.comment_id,
|
notificationId: 'comment_' + wsMessage.post_id + '#' + wsMessage.comment_id,
|
||||||
avatarUrl: getProtocol() + '//point.im/avatar/' + wsMessage.author + '/80',
|
avatarUrl: getProtocol() + '//point.im/avatar/' + wsMessage.author + '/80',
|
||||||
|
@ -493,10 +490,7 @@ $(document).ready(function() {
|
||||||
// @ before username
|
// @ before username
|
||||||
if (options.is('option_at_before_username')) {
|
if (options.is('option_at_before_username')) {
|
||||||
// @todo message response callback processing
|
// @todo message response callback processing
|
||||||
chrome.runtime.sendMessage({
|
messenger.css('css/modules/at_before_username.css');
|
||||||
type: 'injectCSSFiles',
|
|
||||||
files: 'css/modules/at_before_username.css'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.is('option_ajax')) {
|
if (options.is('option_ajax')) {
|
||||||
|
@ -620,7 +614,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
$('#point-plus-debug').fadeOut(1000);
|
$('#point-plus-debug').fadeOut(1000);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
function getProtocol() {
|
function getProtocol() {
|
||||||
return ((location.protocol == 'http:') ? 'http:' : 'https:');
|
return ((location.protocol == 'http:') ? 'http:' : 'https:');
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
"js/bquery_ajax.js",
|
"js/bquery_ajax.js",
|
||||||
|
|
||||||
"js/options-manager.js",
|
"js/options-manager.js",
|
||||||
|
"js/message-sender.js",
|
||||||
|
|
||||||
"js/point-plus.js"
|
"js/point-plus.js"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue