-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
39 lines (35 loc) · 1.24 KB
/
content.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
let video = document.querySelector('video');
let shortcutIcon = document.querySelectorAll('[rel="shortcut icon"]')[0];
const waitForVideo = () => {
video = document.querySelector('video');
shortcutIcon = document.querySelectorAll('[rel="shortcut icon"]')[0];
if (!video || !shortcutIcon) {
timerId = window.setTimeout(waitForVideo, 10);
} else {
chrome.runtime.sendMessage({ msg: 'video_loaded' });
video.addEventListener('ended', event => {
chrome.runtime.sendMessage({ msg: 'video_ended' });
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.msg === 'set_paused') {
if (request.paused) video.pause();
else video.play();
sendResponse({ paused: video.paused });
}
if (request.msg === 'get_paused') {
sendResponse({ paused: video.paused });
}
if (request.msg === 'set_volume') {
video.volume = request.volume;
sendResponse({ volume: video.volume });
}
if (request.msg === 'get_volume') {
sendResponse({ volume: video.volume });
}
if (request.msg === 'set_icon') {
shortcutIcon.href = request.href;
}
});
}
};
waitForVideo();