Created
June 8, 2017 20:45
-
-
Save am4dr/a543e717d60a837fe20088bbf4cb75a4 to your computer and use it in GitHub Desktop.
次の時刻00.000秒ちょうどにページのvideoを再生開始する
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
| /* | |
| * 次の時刻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