-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathmain.js
45 lines (36 loc) · 1.11 KB
/
main.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
window.addEventListener("load", startup, false);
let video;
let logs;
function startup() {
video = document.getElementById("video");
logs = document.getElementById("logs");
if (document.pictureInPictureEnabled) {
document
.querySelector(".no-picture-in-picture")
.remove();
const togglePipButton = document.createElement("button");
togglePipButton.textContent = "Toggle Picture-in-Picture";
togglePipButton.addEventListener("click", togglePictureInPicture, false);
document
.getElementById("controlbar")
.appendChild(togglePipButton);
}
}
function togglePictureInPicture() {
if (document.pictureInPictureElement) {
document.exitPictureInPicture();
} else {
if (document.pictureInPictureEnabled) {
video.requestPictureInPicture()
.then(pictureInPictureWindow => {
pictureInPictureWindow.addEventListener("resize", onPictureInPictureResize, false);
});
}
}
}
function onPictureInPictureResize() {
const listItem = document.createElement("li");
listItem.textContent = `resize - ${Date.now()}`;
logs.appendChild(listItem);
setTimeout(() => logs.removeChild(listItem), 2000);
};