Skip to content

Instantly share code, notes, and snippets.

@am4dr
Created June 8, 2017 20:45
Show Gist options
  • Select an option

  • Save am4dr/a543e717d60a837fe20088bbf4cb75a4 to your computer and use it in GitHub Desktop.

Select an option

Save am4dr/a543e717d60a837fe20088bbf4cb75a4 to your computer and use it in GitHub Desktop.
次の時刻00.000秒ちょうどにページのvideoを再生開始する
/*
* 次の時刻00.000秒ちょうどにページのvideoを再生開始する。
* 対象が唯一のvideo要素であるページで実行可能。
*/
(function () {
const video = document.getElementsByTagName('video')[0];
function delay_play() {
const thre = 200;
const now = new Date();
const wait = (60 - (now.getSeconds())) * 1000 - now.getMilliseconds();
if (wait >= thre + 100) {
setTimeout(() => delay_play(), wait - thre);
console.log('delay_play: wait ' + wait + 'ms');
}
else {
setTimeout(() => video.play(), wait);
}
}
video.currentTime = 0;
delay_play();
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment