-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
46 lines (42 loc) · 1.02 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
let env
if (typeof browser !== 'undefined') env = browser
else env = chrome
const mapIcons = {
0: 'max',
3: 'fhd',
4: 'hd',
5: 'sd',
6: 'ld',
'-1': 'pause',
'-2': 'error',
};
(() => {
env.runtime.onMessage.addListener(message => {
if (message.action === 'updateIcon') {
const type = mapIcons[message.icon]
env.browserAction.setIcon({
path: {
16: `./assets/toolbar/${type}/16.png`,
24: `./assets/toolbar/${type}/24.png`,
32: `./assets/toolbar/${type}/32.png`,
},
})
}
})
env.runtime.onInstalled.addListener(({ reason }) => {
switch (reason) {
case 'install':
env.tabs.getAllInWindow(null, tabs => {
tabs.forEach(tab => {
const { hostname, pathname } = new URL(tab.url)
if (hostname === 'www.youtube.com' && pathname === '/watch') {
env.tabs.executeScript(tab.id, { file: 'index.js' })
}
})
})
break
default:
break
}
})
})()