aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/static/js/transcript-table.js
diff options
context:
space:
mode:
authorzrose584 <57181548+zrose584@users.noreply.github.com>2020-09-15 20:32:12 +0200
committerzrose584 <57181548+zrose584@users.noreply.github.com>2020-09-15 20:32:12 +0200
commitb3de26606dcdb374a98a494136d2c3f210fff838 (patch)
treecbf8646ad010cb3eb306f8aafb0b152e24969d3a /youtube/static/js/transcript-table.js
parent0be0a59a2a3eef8da75f2bae57df72526598b2bf (diff)
downloadyt-local-b3de26606dcdb374a98a494136d2c3f210fff838.tar.lz
yt-local-b3de26606dcdb374a98a494136d2c3f210fff838.tar.xz
yt-local-b3de26606dcdb374a98a494136d2c3f210fff838.zip
handle firefox' VTT parsing bug
from #15: "[..] Firefox's VTT parsing [ignores] newlines. So if the cue starts with a newline, that cue will have blank text (a corollary is that the first sentence uttered will fail to display in the automatic captions [..])."
Diffstat (limited to 'youtube/static/js/transcript-table.js')
-rw-r--r--youtube/static/js/transcript-table.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/youtube/static/js/transcript-table.js b/youtube/static/js/transcript-table.js
index acc2703..d0028f7 100644
--- a/youtube/static/js/transcript-table.js
+++ b/youtube/static/js/transcript-table.js
@@ -4,6 +4,8 @@ function renderCues() {
var tt = Q("video").textTracks[select_tt.selectedIndex];
let cuesL = [...tt.cues];
var tt_type = cuesL[0].text.startsWith(" \n");
+ let ff_bug = false;
+ if (!cuesL[0].text.length) { ff_bug = true; tt_type = true };
let rows;
function forEachCue(cb) {
@@ -11,7 +13,8 @@ function renderCues() {
let txt, startTime = tt.cues[i].startTime;
if (tt_type) {
if (i % 2) continue;
- txt = tt.cues[i].text.split('\n')[1].replace(/<[\d:.]*?><c>(.*?)<\/c>/g, "$1");
+ if (ff_bug && !tt.cues[i].text.length) txt = tt.cues[i+1].text;
+ else txt = tt.cues[i].text.split('\n')[1].replace(/<[\d:.]*?><c>(.*?)<\/c>/g, "$1");
} else {
txt = tt.cues[i].text;
}
@@ -52,7 +55,7 @@ function renderCues() {
else {
forEachCue((startTime, txt) => {
span = document.createElement("span");
- var idx = txt.indexOf(" ");
+ var idx = txt.indexOf(" ", 1);
var [firstWord, rest] = [txt.slice(0, idx), txt.slice(idx)];
span.appendChild(createA(startTime, firstWord, toMS(startTime)));
@@ -90,8 +93,8 @@ function loadCues() {
var iC = setInterval(() => {
if (tt.cues && tt.cues.length) {
- renderCues();
clearInterval(iC);
+ renderCues();
}
}, 100);
}