-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (29 loc) · 1.05 KB
/
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
32
33
//tmdb api key stored in api-keys.js in as const tmdb_api_key
chrome.runtime.onMessage.addListener(async (response, sender, callBack) => {
if ("get" in response) {
switch (response.get) {
case "api":
const key_list = {
tmdb: tmdb_api_key
}
callBack({ keys: key_list }); break;
case "estimate":
if (!("tt" in response)) {
callBack({ error: "missing tt" }); break;
}
const estimate = await estimate_full_size(response.tt);
console.log(estimate);
callBack({ estimation: estimate }); break;
default:
callBack({}); break;
}
}
})
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, current_tab) => {
if (/^https:\/\/www\.imdb\.com/.test(current_tab.url)) {
const url_changed = "url" in changeInfo;
if (url_changed) {
chrome.tabs.sendMessage(tabId,{url:changeInfo.url});
}
}
});