diff options
author | James Taylor <28744867+user234683@users.noreply.github.com> | 2020-09-24 12:14:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 12:14:20 -0700 |
commit | 97b092bf7ad9caa6e639c3672a9917cefdd18d40 (patch) | |
tree | 38edb18c56feec9a20c1eed08cc816c39dc03b98 /youtube/static/js/common.js | |
parent | e829cc0e89c81f7b6ba0b9cea1d2d95f84951308 (diff) | |
parent | 0830468bd13b59323f244978ae3e915bb715a949 (diff) | |
download | yt-local-97b092bf7ad9caa6e639c3672a9917cefdd18d40.tar.lz yt-local-97b092bf7ad9caa6e639c3672a9917cefdd18d40.tar.xz yt-local-97b092bf7ad9caa6e639c3672a9917cefdd18d40.zip |
Merge pull request #15 from zrose584/transcript_table
Transcript table
Diffstat (limited to 'youtube/static/js/common.js')
-rw-r--r-- | youtube/static/js/common.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/youtube/static/js/common.js b/youtube/static/js/common.js new file mode 100644 index 0000000..4c7ee51 --- /dev/null +++ b/youtube/static/js/common.js @@ -0,0 +1,32 @@ +Q = document.querySelector.bind(document); +function text(msg) { return document.createTextNode(msg); } +function clearNode(node) { while (node.firstChild) node.removeChild(node.firstChild); } +function toMS(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); +} + + +var cur_tt_idx = 0; +function getActiveTranscriptTrackIdx() { + let tts = Q("video").textTracks; + if (!tts.length) return; + for (let i=0; i < tts.length; i++) { + if (tts[i].mode == "showing") { + cur_tt_idx = i; + return cur_tt_idx; + } + } + return cur_tt_idx; +} +function getActiveTranscriptTrack() { return Q("video").textTracks[getActiveTranscriptTrackIdx()]; } + +function getDefaultTranscriptTrackIdx() { + let tts = Q("video").textTracks; + return tts.length - 1; +} + +window.addEventListener('DOMContentLoaded', function() { + cur_tt_idx = getDefaultTranscriptTrackIdx(); +}); |