PageAction: display on init and tab switch if activated
This commit is contained in:
parent
75b40ece52
commit
56131220a2
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue