PageAction: display on init and tab switch if activated

This commit is contained in:
ikipatang 2017-11-26 23:54:55 +01:00
parent 75b40ece52
commit 56131220a2

View file

@ -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 Listeners
*/ */
browser.tabs.onActivated.addListener(tabActivation);
browser.browserAction.onClicked.addListener(shareCurrentTab); browser.browserAction.onClicked.addListener(shareCurrentTab);
browser.pageAction.onClicked.addListener(shareCurrentTab); browser.pageAction.onClicked.addListener(shareCurrentTab);