-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
32 lines (28 loc) · 1.02 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
// Establish a long-lived connection
let port = chrome.runtime.connect({name: "playpause"});
window.onload = function() {
var video = document.querySelector('video');
if(video) {
console.log('Video element found'); // Logs when the video element is found
} else {
console.log('Video element not found'); // Logs when the video element is not found
return;
}
var isPaused = video.paused;
port.postMessage({isPaused: isPaused, command: isPaused ? 'play' : 'pause'});
video.onplay = function() {
isPaused = false;
console.log('Video play/pause status changed');
port.postMessage({isPaused: isPaused, command: 'pause'});
};
video.onpause = function() {
isPaused = true;
console.log('Video play/pause status changed');
port.postMessage({isPaused: isPaused, command: 'play'});
};
};
// Listen for disconnections
port.onDisconnect.addListener(function() {
console.log("Disconnected from background script");
port = null;
});