I want the video in a youtube playlist to go to the next video when it reaches the second I want. But I can't check the location.href all the time, I want the code to run when the same url is opened again because I loop the playlist.
const counterEle = document.querySelector("video");
function generateCount(limit) {
mutation(160.510023);
if (counterEle.currentTime > limit) {
console.log("current > limit");
} else {
setTimeout(generateCount, 3000, limit);
setTimeout(mutation, 3000, limit);
}
}
let previousUrl = 'https://www.youtube.com/watch?v=93qE6Z8qheA&list=PL9dIg-VwAsxZdZvuHjzTOP8-49CWpis17&index=5';
const observer = new MutationObserver(mutation);
function mutation(limit) {
generateCount(160.510023);
if (location.href == previousUrl) {
console.log(`URL changed to ${location.href}`);
if (counterEle.currentTime > limit) {
document
.querySelector(
"#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > a.ytp-next-button.ytp-button"
)
.click();
} else {
setTimeout(generateCount, 3000);
}
} else {
console.log("!=");
}
}
I tried many methods, what am I doing wrong?
(There is no problem with the code working, just checking the domain name is a problem)