Skip to content

Instantly share code, notes, and snippets.

@Anderson-Juhasc
Created February 12, 2025 12:54
Show Gist options
  • Save Anderson-Juhasc/cf3d89e5e05ffd3a7143245659b8ffb6 to your computer and use it in GitHub Desktop.
Save Anderson-Juhasc/cf3d89e5e05ffd3a7143245659b8ffb6 to your computer and use it in GitHub Desktop.
Youtube feature of repeat
(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