-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyt-loop-script.js
More file actions
43 lines (30 loc) · 998 Bytes
/
Copy pathyt-loop-script.js
File metadata and controls
43 lines (30 loc) · 998 Bytes
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
//YtLoopExtension script
console.log("Hii")
const checkControlBar = setInterval(()=> {
let controlBar = document.querySelector(".ytp-right-controls")
if (controlBar) {
// Proceed to add your button
const loopButton = document.createElement("button");
loopButton.innerText = "Loop"
loopButton.classList.add("ytp-loop-button", "ytp-button", )
loopButton.setAttribute("title", "Loop Video")
controlBar.appendChild(loopButton)
const video = document.querySelector("video")
console.log(video)
let isLooping = false;
loopButton.addEventListener("click",() => {
//toggle loop state
isLooping = !isLooping
video.loop = isLooping;
console.log("yup itt clicked")
//let user know the state
if(isLooping) {
loopButton.classList.add("ytp-loop-active");
} else {
loopButton.classList.remove("ytp-loop-active")
}
})
//stop the interval
clearInterval(checkControlBar)
}
}, 500);