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);