From 56131220a2be29e856286eb49f0f9ea7c7ddf351 Mon Sep 17 00:00:00 2001 From: ikipatang <5412352+ikipatang@users.noreply.github.com> Date: Sun, 26 Nov 2017 23:54:55 +0100 Subject: [PATCH] PageAction: display on init and tab switch if activated --- src/background.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/background.js b/src/background.js index 4ec9323..1e4d8c7 100644 --- a/src/background.js +++ b/src/background.js @@ -30,8 +30,38 @@ function shareCurrentTab(tab) { }); } +/** + * Show Page Action on current page if activated + * @param {string} tabId - Current tab id + * @return {void} - + */ +function showPageAction(tabId){ + browser.storage.local.get().then((storage) => { + if(storage.pageAction){ + browser.pageAction.show(tabId); + } + }); +} + +/** + * Show page action with given active information + * @param {object} activeInfo - + * @return {void} - + */ +function tabActivation(activeInfo){ + showPageAction(activeInfo.tabId); +} + +/* +Initialize + */ +browser.tabs.query({active: true, currentWindow: true}).then((tabs) => { + showPageAction(tabs[0].id); +}); + /* Listeners */ +browser.tabs.onActivated.addListener(tabActivation); browser.browserAction.onClicked.addListener(shareCurrentTab); browser.pageAction.onClicked.addListener(shareCurrentTab);