-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
31 lines (28 loc) · 893 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function doLoadSidebar() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
const tab = tabs[0];
if(!window.browser) {
// Message to content script
chrome.tabs.sendMessage(tab.id, {kind: "toggle", url: tab.url});
} else {
// Message to sidebar document
browser.runtime.sendMessage({url: tab.url});
}
});
}
if(window.browser) {
browser.sidebarAction.setPanel({panel: 'sidebar.html'});
chrome.tabs.onActivated.addListener(doLoadSidebar);
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if(changeInfo.status === 'loading' && changeInfo.url !== undefined) doLoadSidebar();
});
browser.browserAction.onClicked.addListener(() => {
browser.sidebarAction.toggle();
return true;
});
} else {
chrome.browserAction.onClicked.addListener(function(tab){
doLoadSidebar();
return true;
});
}