-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
56 lines (52 loc) · 1.71 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// if (changeInfo.status === "complete" && /^http/.test(tab.url)) {
// chrome.scripting
// .executeScript({
// target: { tabId: tabId },
// files: ["./getMultimedias.js"],
// })
// .then((res) => {
// console.log("executed getMultimedias script");
// })
// .catch((err) => console.log(err));
// }
// });
const executeScripstOnTab = (tabId, files) => {
chrome.scripting
.executeScript({
target: { tabId: tabId },
files,
})
.then((res) => {
console.log("executed getMultimedias script");
})
.catch((err) => console.log(err));
};
// If you have access to someone else's public watchlist, this will still return true.
const imdbWatchlistUrlRegex = (url) => /.*imdb.com.*watchlist.*/.test(url);
const urlIsImdbWatchlistPage = (url) => {
const itIsWatchlistPage = imdbWatchlistUrlRegex(url);
chrome.runtime.sendMessage({
message: "watchlist_url_validation",
payload: itIsWatchlistPage,
});
return itIsWatchlistPage;
};
chrome.runtime.onMessage.addListener((request, sender) => {
if (request.message && request.message === "scan_watchlist") {
chrome.tabs.query(
{ currentWindow: true, active: true },
function (tabArray) {
const activeTab = tabArray[0];
if (tabArray && activeTab && urlIsImdbWatchlistPage(activeTab.url)) {
executeScripstOnTab(activeTab.id, ["./getMultimedias.js"]);
// executeScripstOnTab(activeTab.id, [
// "./misc/getMultimediasToDebug.js",
// ]);
} else {
console.log("Page is not a watchlist page or no active tab");
}
}
);
}
});