-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
41 lines (26 loc) · 931 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
32
33
34
35
36
37
38
39
40
41
var activeVideos = {};
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("background.js got a message")
if(request==="READY" && activeVideos.hasOwnProperty(sender.tab.id)){
// The content script on the other side is ready
sendResponse("NEWVID");
}
});
chrome.tabs.onUpdated.addListener((tabid, cinfo, tab)=>{
if(tab.url && tab.url.includes("youtube.com/watch")){
const params = tab.url.split("?")[1];
const urlparams = new URLSearchParams(params);
activeVideos[tabid] = {
type : "NEWVID",
id : urlparams.get("v")
}
}
});
chrome.runtime.onInstalled.addListener((reason) => {
if (reason === chrome.runtime.OnInstalledReason.INSTALL) {
// WHen the user firsts install the extensions
chrome.tabs.create({
url: 'about.html'
});
}
});