From a600cb8d30d7e82c1888e15bdaf2d9a20651c245 Mon Sep 17 00:00:00 2001 From: podhmo Date: Sat, 29 Jun 2019 23:14:50 +0900 Subject: [PATCH] feat: show current color --- firefox/background.js | 30 +++++++++++++++++++++++++++++- firefox/contentScript.js | 17 ++++++++++++----- firefox/manifest.json | 3 ++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/firefox/background.js b/firefox/background.js index 5305fb6..b8d899d 100644 --- a/firefox/background.js +++ b/firefox/background.js @@ -30,8 +30,18 @@ browser.browserAction.onClicked.addListener(function (tab){ const nextEnabled = !config.enable; updateStatus(config, nextEnabled, function(){ + if (nextEnabled) { + browser.tabs.query({currentWindow: true, active: true}, (tabs) =>{ + tabs.forEach((tab) => { + browser.tabs.sendMessage(tab.id, {"action": "moved"}); + }); + }); + } else { + browser.theme.update({}); + } + browser.tabs.query({currentWindow: true}, (tabs) =>{ - const action = nextEnabled ? "activate" : "deactivate"; // xxx: + const action = nextEnabled ? "enabled" : "disabled"; // xxx: tabs.forEach((tab) => { browser.tabs.sendMessage(tab.id, {"action": action}); }); @@ -39,3 +49,21 @@ browser.browserAction.onClicked.addListener(function (tab){ }); }); }); + +browser.tabs.onUpdated.addListener((tabId) => { + browser.tabs.sendMessage(tabId, {"action": "moved"}); +}); + +browser.runtime.onMessage.addListener(async (request) =>{ + if (!request.action || request.action !== "after-extract") { + return ; + } + + const theme = { + colors: { + bookmark_text: request.options.fgColor, + toolbar: request.options.bgColor + } + } + browser.theme.update(theme); +}); diff --git a/firefox/contentScript.js b/firefox/contentScript.js index 1f748f0..54d683e 100644 --- a/firefox/contentScript.js +++ b/firefox/contentScript.js @@ -18,16 +18,24 @@ browser.runtime.onMessage.addListener((request) =>{ return; } switch (request.action) { - case "deactivate": + case "disabled": view.refresh(); break; - case "activate": + case "enabled": browser.storage.local.get("config", ({config}) =>{ const {hostname, options} = info.extract(getHostname(), config); view.draw(hostname, options); - return; }) break; + case "moved": + browser.storage.local.get("config", ({config}) =>{ + if (!config.enable) { + return; + } + const {hostname, options} = info.extract(getHostname(), config); + browser.runtime.sendMessage({action: "after-extract", options: options}); + }); + break; default: console.warn("unexpected action: %s", request.action); } @@ -43,8 +51,7 @@ browser.storage.local.get("config", ({config}) =>{ } const {hostname, options} = info.extract(getHostname(), config); - + browser.runtime.sendMessage({action: "after-extract", options: options}) view.refresh(); view.draw(hostname, options); }); - diff --git a/firefox/manifest.json b/firefox/manifest.json index 032f44c..893d4f5 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -33,7 +33,8 @@ "permissions": [ "storage", "activeTab", - "tabs" + "tabs", + "theme" ], "short_name": "hostnameColor", "version": "0.0.0"