Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created April 19, 2015 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamchau/b02c6c8a64d0a384ae18 to your computer and use it in GitHub Desktop.
Save lamchau/b02c6c8a64d0a384ae18 to your computer and use it in GitHub Desktop.
youtube infinite repeater
(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();
})();
@lamchau
Copy link
Author

lamchau commented Apr 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment