[gnome-browser-extension/wip/refactor: 1/7] Allow to use multiple extensions websites




commit e10ef30ba6b1cba48dbfa7911cf27ce76736c052
Author: Yuri Konotopov <ykonotopov gmail com>
Date:   Wed Nov 16 18:14:39 2016 +0300

    Allow to use multiple extensions websites
    
    This is for debug purposes only - it's much easier to add local debug
    sites to array

 extension/extension.js         | 22 +++++++++++++++-------
 extension/include/constants.js |  4 +++-
 extension/manifest.json        |  8 ++++++--
 3 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/extension/extension.js b/extension/extension.js
index 8a851d0..1c41f37 100644
--- a/extension/extension.js
+++ b/extension/extension.js
@@ -26,7 +26,11 @@ chrome.runtime.onInstalled.addListener(function(details) {
 });
 
 chrome.runtime.onMessageExternal.addListener(function (request, sender, sendResponse) {
-       if (sender.url.startsWith(EXTENSIONS_WEBSITE))
+       if (
+               EXTENSIONS_WEBSITE.reduce(
+                       (accumulator, url) => accumulator + sender.url.startsWith(url),
+                       0)
+       )
        {
                if (request && request.execute)
                {
@@ -72,10 +76,12 @@ chrome.runtime.onMessageExternal.addListener(function (request, sender, sendResp
        }
 });
 
-chrome.browserAction.onClicked.addListener(function () {
-       chrome.tabs.create({
-               url: EXTENSIONS_WEBSITE,
-               active: true
+EXTENSIONS_WEBSITE.forEach(url => {
+       chrome.browserAction.onClicked.addListener(function () {
+               chrome.tabs.create({
+                       url: url,
+                       active: true
+               });
        });
 });
 
@@ -105,8 +111,9 @@ port.onMessage.addListener(function (message) {
                        /*
                         * Send events to opened extensions.gnome.org tabs
                         */
-                       chrome.tabs.query({
-                                       url: EXTENSIONS_WEBSITE + '*'
+                       EXTENSIONS_WEBSITE.forEach(url => {
+                               chrome.tabs.query({
+                                       url: url + '*'
                                },
                                function (tabs) {
                                        for (k in tabs)
@@ -114,6 +121,7 @@ port.onMessage.addListener(function (message) {
                                                chrome.tabs.sendMessage(tabs[k].id, message);
                                        }
                                });
+                       });
 
                        /*
                         * Route message to Options page.
diff --git a/extension/include/constants.js b/extension/include/constants.js
index f48d514..ee57f20 100644
--- a/extension/include/constants.js
+++ b/extension/include/constants.js
@@ -37,7 +37,9 @@ EXTENSION_CHANGED_ERROR                       = 2;
 
 NATIVE_HOST                            = 'org.gnome.chrome_gnome_shell';
 
-EXTENSIONS_WEBSITE                     = 'https://extensions.gnome.org/';
+EXTENSIONS_WEBSITE                     = [
+       'https://extensions.gnome.org/',
+];
 UPDATE_URL                             = EXTENSIONS_WEBSITE + 'update-info/';
 
 DEFAULT_SYNC_OPTIONS                   = {
diff --git a/extension/manifest.json b/extension/manifest.json
index d96ed27..acee223 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -32,7 +32,9 @@
 
   "content_scripts": [
     {
-      "matches": ["https://extensions.gnome.org/*";],
+      "matches": [
+        "https://extensions.gnome.org/*";
+    ],
       "run_at": "document_start",
       "js": [
            "include/constants.js",
@@ -42,7 +44,9 @@
     }
   ],
   "externally_connectable": {
-      "matches": ["https://extensions.gnome.org/*";]
+      "matches": [
+        "https://extensions.gnome.org/*";
+    ]
   },
   "options_ui": {
     "page": "options.html",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]