Created
February 12, 2025 12:54
-
-
Save Anderson-Juhasc/cf3d89e5e05ffd3a7143245659b8ffb6 to your computer and use it in GitHub Desktop.
Youtube feature of repeat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
// Wait for the YouTube player to load | |
function waitForPlayer() { | |
const player = document.querySelector('.html5-video-player'); | |
if (player) { | |
setupRepeatFeature(player); | |
} else { | |
setTimeout(waitForPlayer, 500); | |
} | |
} | |
// Set up the repeat feature | |
function setupRepeatFeature(player) { | |
const videoElement = player.querySelector('video'); | |
if (!videoElement) { | |
console.warn('YouTube video element not found.'); | |
return; | |
} | |
console.log('Repeat feature enabled.'); | |
// Attach an event listener to the video | |
videoElement.addEventListener('ended', () => { | |
console.log('Video ended. Restarting...'); | |
videoElement.currentTime = 0; // Restart from the beginning | |
videoElement.play(); // Play the video | |
}); | |
} | |
// Initialize | |
waitForPlayer(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment