-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
28 lines (25 loc) · 981 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
const app_name = browser.runtime.getManifest().short_name;
const stremio_url = '*://web.stremio.com/*';
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (changeInfo.status === 'loading') {
let tabs = await browser.tabs.query({url: stremio_url});
if (typeof port === 'undefined' && tabs.length > 0) {
port = browser.runtime.connectNative(app_name);
} else if (typeof port === 'object' && tabs.length === 0) {
port.disconnect();
delete port;
}
}
});
browser.tabs.onRemoved.addListener(async (tabId, removeInfo) => {
if (typeof port === 'object') {
let tabs = await browser.tabs.query({url: stremio_url});
if (tabs.length === 0 || (tabs.length === 1 && tabs[0].id === tabId)) {
port.disconnect();
delete port;
}
}
});
browser.action.onClicked.addListener(() => {
browser.tabs.create({url: "https://web.stremio.com"})
});