diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-09-24 14:44:21 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-09-24 14:44:21 -0700 |
commit | 0a5088f1e503f43f06b30f709e6aa4e5947d2aca (patch) | |
tree | 49541ae97ee23535dda4139b2df0739bfd8932cc /youtube/static/js/common.js | |
parent | c7c74624edafd66b5b6cb63ed5fa87aad08cb65f (diff) | |
download | yt-local-0a5088f1e503f43f06b30f709e6aa4e5947d2aca.tar.lz yt-local-0a5088f1e503f43f06b30f709e6aa4e5947d2aca.tar.xz yt-local-0a5088f1e503f43f06b30f709e6aa4e5947d2aca.zip |
Transcript table: Fix timestamps for videos longer than an hour
See #15
Diffstat (limited to 'youtube/static/js/common.js')
-rw-r--r-- | youtube/static/js/common.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/youtube/static/js/common.js b/youtube/static/js/common.js index 8f27a64..687c6fa 100644 --- a/youtube/static/js/common.js +++ b/youtube/static/js/common.js @@ -1,10 +1,19 @@ Q = document.querySelector.bind(document); function text(msg) { return document.createTextNode(msg); } function clearNode(node) { while (node.firstChild) node.removeChild(node.firstChild); } -function toTimestamp(s) { - var s = Math.floor(s); - var m = Math.floor(s/60); var s = s % 60; - return `0${m}:`.slice(-3) + `0${s}`.slice(-2); +function toTimestamp(seconds) { + var seconds = Math.floor(seconds); + + var minutes = Math.floor(seconds/60); + var seconds = seconds % 60; + + var hours = Math.floor(minutes/60); + var minutes = minutes % 60; + + if (hours) { + return `0${hours}:`.slice(-3) + `0${minutes}:`.slice(-3) + `0${seconds}`.slice(-2); + } + return `0${minutes}:`.slice(-3) + `0${seconds}`.slice(-2); } |