From 0a5088f1e503f43f06b30f709e6aa4e5947d2aca Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 24 Sep 2020 14:44:21 -0700 Subject: Transcript table: Fix timestamps for videos longer than an hour See #15 --- youtube/static/js/common.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'youtube/static') 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); } -- cgit v1.2.3