bep40 commited on
Commit
10c8144
·
verified ·
1 Parent(s): f5d4a7d

Fix VTV: add safety net pinBlock on DOMContentLoaded to prevent race condition

Browse files
Files changed (1) hide show
  1. static/yt_live.js +16 -4
static/yt_live.js CHANGED
@@ -350,7 +350,6 @@
350
  CHANNELS.forEach(ch=>{
351
  const i=d[ch.id];
352
  if(i&&i.stream_url){
353
- // Store direct URL + proxied fallback
354
  STREAMS[ch.id]=[i.stream_url, proxyUrl(i.stream_url)];
355
  } else STREAMS[ch.id]=[];
356
  });
@@ -443,9 +442,22 @@
443
  window.loadHome.__vtvWrapped=true;
444
  }
445
 
446
- // Also auto-insert on home if view-home exists
447
- if(document.getElementById('view-home')&&!document.getElementById('vtv-block')){
448
- pinBlock();
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  }
450
 
451
  window._vtvPinBlock=pinBlock;
 
350
  CHANNELS.forEach(ch=>{
351
  const i=d[ch.id];
352
  if(i&&i.stream_url){
 
353
  STREAMS[ch.id]=[i.stream_url, proxyUrl(i.stream_url)];
354
  } else STREAMS[ch.id]=[];
355
  });
 
442
  window.loadHome.__vtvWrapped=true;
443
  }
444
 
445
+ // Safety net: ensure VTV block is pinned even if loadHome wrapper didn't fire
446
+ // This handles the race condition where app_v2.js calls loadHome() before yt_live.js loads
447
+ if(document.readyState==='loading'){
448
+ document.addEventListener('DOMContentLoaded',function(){
449
+ setTimeout(function(){
450
+ if(document.getElementById('view-home')&&!document.getElementById('vtv-block')){
451
+ pinBlock();
452
+ }
453
+ },200);
454
+ });
455
+ }else{
456
+ setTimeout(function(){
457
+ if(document.getElementById('view-home')&&!document.getElementById('vtv-block')){
458
+ pinBlock();
459
+ }
460
+ },200);
461
  }
462
 
463
  window._vtvPinBlock=pinBlock;