diff --git a/chrome_point_plus/js/background.js b/chrome_point_plus/js/background.js index 8beb756..e8a0516 100644 --- a/chrome_point_plus/js/background.js +++ b/chrome_point_plus/js/background.js @@ -40,7 +40,7 @@ function injectJS(tabId, files, onAllInjected) { // Message listener chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { // @todo Check if sender.tab may be undefined in some cases - console.log('Received message from tab #%i: %O', sender.tab.id, message); + console.log('Received message from tab #%s: %O', sender.tab ? sender.tab.id : 'undefined', message); if (message) { switch (message.type) { @@ -74,6 +74,11 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { return true; break; + case 'getManifestVersion': + sendResponse({version: getVersion()}); + return true; + break; + case 'listenNotificationClicks': // Adding notification click event listener chrome.notifications.onClicked.addListener(function(notificationId) { @@ -186,7 +191,12 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { }); // Getting version from manifest.json -function getVersion() { +function getVersion() { + /** + * @deprecated XMLHttpRequest in the background worker is deprecated + * according to the Chrome warning. But we definitely need synchronous + * AJAX here + */ var xhr = new XMLHttpRequest(); xhr.open('GET', chrome.extension.getURL('manifest.json'), false); xhr.send(null); diff --git a/chrome_point_plus/js/options.js b/chrome_point_plus/js/options.js index 2cee9a6..07773e6 100644 --- a/chrome_point_plus/js/options.js +++ b/chrome_point_plus/js/options.js @@ -1,19 +1,3 @@ -/** - * Получает версию настроек из манифеста - * @returns {String} Версия настроек - */ -function getVersion() { - var xhr = new XMLHttpRequest(), - manifest; - - xhr.open('GET', chrome.extension.getURL('manifest.json'), false); - xhr.send(null); - - manifest = JSON.parse(xhr.responseText); - - return manifest.version; -} - /** * Объект, управляющий сохранением настроек на странице настроек * @@ -21,14 +5,20 @@ function getVersion() { * @constructor */ function Options() { - this.version = getVersion(); this.form = document.querySelector('form'); - this.showVersion(); - this.restore(); - - this.form.addEventListener('change', this._onChange.bind(this)); this.listenTabs(); + + chrome.runtime.sendMessage(null, { + type: 'getManifestVersion' + }, null, function(response) { + this.version = response.version || 'undefined'; + + this.showVersion(); + this.restore(); + + this.form.addEventListener('change', this._onChange.bind(this)); + }.bind(this)); } /** diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index d14bb8b..bb60098 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -5,6 +5,7 @@ chrome.runtime.sendMessage({ console.debug('showPageAction response: %O', response); }); +// @todo Move OptionsManager to the separate file /** * Объект для получения опций * @param {Object} options Хеш настроек @@ -43,10 +44,18 @@ OptionsManager.prototype.getOptions = function() { return this._options; }; +var ppVersion; + +chrome.runtime.sendMessage(null, { + type: 'getManifestVersion' +}, null, function(response) { + ppVersion = response.version || 'undefined'; +}); + $(document).ready(function() { // Grouping console log console.group('point-plus'); - console.info('Point+ %s', getVersion()); + console.info('Point+ %s', ppVersion); // Проверяем, загрузились ли мы var point_plus_debug = $('#point-plus-debug'); @@ -55,8 +64,8 @@ $(document).ready(function() { return; } $('
').attr({ - 'data-point-plus-version': getVersion() - }).text('Point+ ' + getVersion() + ' loading...') + 'data-point-plus-version': ppVersion + }).text('Point+ ' + ppVersion + ' loading...') .insertBefore('#user-menu-cb'); // Черновики. Ставим хандлер и восстанавливаем предыдущее состояние diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index 8ddd8dd..6674a24 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -29,10 +29,8 @@ "js": [ "vendor/jquery/jquery.min.js", - "js/markitup/sets/markdown/set.js", - "js/bquery_ajax.js", - "js/options.js", + "js/point-plus.js" ], "css": [ @@ -57,6 +55,7 @@ "http://player.soundcloud.com/*", "https://player.soundcloud.com/*", "https://api.kanaria.ru/point/*", + "https://*.twitter.com/*", "storage", "notifications", "tabs"