-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
87 lines (77 loc) · 2.07 KB
/
Copy pathbackground.js
File metadata and controls
87 lines (77 loc) · 2.07 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
browser.runtime.onStartup.addListener(() => {
browser.storage.local.clear();
});
browser.tabs.onActivated.addListener(async (activeInfo) => {
await browser.scripting.executeScript({
target: {
tabId: activeInfo.tabId,
},
files: ["browser-polyfill.js"],
});
await browser.scripting.executeScript({
target: {
tabId: activeInfo.tabId,
},
args: [activeInfo.tabId],
func: (tabId) => {
let video = document.querySelector("video");
browser.storage.sync
.get(["autoResume", "respectPause"])
.then(({ autoResume, respectPause }) => {
if (!respectPause && autoResume) {
video.play();
return;
}
browser.storage.local.get(`tab${tabId}`).then(
(items) => {
console.log(items);
if (!items[`tab${tabId}`]) {
video.play();
}
},
(err) => {
console.error(err);
}
);
});
},
});
let tabs = await browser.tabs.query({ active: false });
for (let tab of tabs) {
await browser.scripting.executeScript({
target: {
tabId: tab.id,
},
files: ["browser-polyfill.js"],
});
await browser.scripting.executeScript({
target: {
tabId: tab.id,
},
args: [tab.id],
func: (tabId) => {
let video = document.querySelector("video");
browser.storage.sync.get(["respectPause"]).then(({ respectPause }) => {
if (respectPause) {
if (video.paused) {
browser.storage.local
.set({ [`tab${tabId}`]: true })
.then(() => {})
.catch((err) => {
console.error(err);
});
} else {
browser.storage.local
.set({ [`tab${tabId}`]: false })
.then(() => {})
.catch((err) => {
console.error(err);
});
}
}
});
video.pause();
},
});
}
});