LoopYT

A redirectless bookmarklet for looping YouTube videos

View the Project on GitHub pglass/loop_yt

This is a redirectless bookmarklet in pure JavaScript for looping either Flash or HTML5 YouTube videos. It works under both Firefox and Chrome.

How to use it: Drag the LoopYT bookmarklet to your bookmarks. On a YouTube video page, click the bookmarklet. The video will then repeat indefinitely. You will see start/stop text entries below the video where you can specify a particular portion of the video to loop over.

Why: Other bookmarklets that I've found for looping a YouTube video send you away from YouTube to a website like youtubeonrepeat.com that tries to replicate some of YouTube's functionality, but fails to be identical. This script is faster, since it avoids the redirect, and it leaves all of YouTube's functionality intact.

How it works: Part of the script finds the video element in the page, and decides whether it's an HTML5 or Flash video. While HTML5 videos have built-in support for looping (via the loop flag), HTML5 doesn't seem to support looping between arbitrary start and stop times. For both Flash and HTML5, setInterval is used to check if we're out of bounds of the start/stop times, or if the video has ended. Then the video is seeked back to the start time, using the YouTube API for Flash videos, and using built-in functionality for HTML5 videos.

Problems/Todo