Created
April 19, 2015 09:28
-
-
Save lamchau/b02c6c8a64d0a384ae18 to your computer and use it in GitHub Desktop.
youtube infinite repeater
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() { | |
if (!/youtube.com$/i.test(location.host)) { | |
alert("hostname does not match 'youtube.com'"); | |
return; | |
} | |
var timeout; | |
var resume; | |
var repeat = function repeat() { | |
clearTimeout(timeout); | |
var play_button = document.querySelector('.ytp-button.ytp-button-play'); | |
// paused | |
if (play_button) { | |
resume = function() { | |
play_button.removeEventListener('click', resume); | |
setTimeout(repeat, 50); | |
}; | |
play_button.addEventListener('click', resume); | |
return; | |
} | |
var progress_bar = document.querySelector('.html5-progress-bar.ytp-force-transform.red'); | |
var replay_button = document.querySelector('.ytp-button.ytp-button-replay'); | |
var current = +progress_bar.getAttribute('aria-valuenow'); | |
var max = +progress_bar.getAttribute('aria-valuemax'); | |
var countdown = ((max - current) * 1000) + 50; | |
if (replay_button) { | |
replay_button.click(); | |
} | |
timeout = setTimeout(repeat, countdown); | |
} | |
repeat(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bookmarklet: http://jsfiddle.net/lchau/55L68j45/