Saturday, January 16, 2016

Loop-play YouTube video

OBSOLETE: Just right click the video then click "Loop".

Sometimes, you want to play YouTube video endlessly (when listening song for example). This is a simple trick which does that.

Please note that it only work with YouTube HTML5 Player. DOES NOT WORK WITH YOUTUBE FLASH PLAYER!!!

Just bookmark link below:
Loop
Unloop

When you're playing video in YouTube, just click the "Loop" bookmark and the video will start playing endlessly.

If you're curious about the code: here it is

Loop:

document.getElementsByClassName("video-stream html5-main-video")[0].setAttribute("loop","")

Unloop:
document.getElementsByClassName("video-stream html5-main-video")[0].removeAttribute("loop")

Now the explanation:

First of all, we find a tag with video-stream html5-main-video class (document.getElementsByClassName) and only select the first result (as there will be only one result) ([0]). Next, we set attribute loop to it (setAttribute("loop","")) (the second argument is unused).

No comments:

Post a Comment