Spaces:
Running
Running
fix: popup iframe loading - async src, loader timeout, fallback to new tab
Browse files- static/yt_live.js +28 -8
static/yt_live.js
CHANGED
|
@@ -164,7 +164,8 @@
|
|
| 164 |
.vtv-popup-header{display:flex;align-items:center;justify-content:space-between;padding:8px 12px;background:#111;border-bottom:1px solid #333}
|
| 165 |
.vtv-popup-title{font-size:14px;font-weight:700;color:#00ccff}
|
| 166 |
.vtv-popup-close{background:#333;border:none;color:#fff;font-size:18px;width:32px;height:32px;border-radius:6px;cursor:pointer}
|
| 167 |
-
.vtv-popup-frame{flex:1;position:relative;background:#000;min-height:
|
|
|
|
| 168 |
.vtv-popup-frame iframe{position:absolute;inset:0;width:100%;height:100%;border:none}
|
| 169 |
.vtv-popup-loader{display:flex;align-items:center;justify-content:center;height:280px;color:#00ccff;font-size:12px;flex-direction:column;gap:8px}
|
| 170 |
.vtv-popup-btn{background:#1a2a3a;border:1px solid #2a3a4a;color:#8ab4d8;font-size:9px;padding:3px 8px;border-radius:6px;cursor:pointer;margin-left:4px}
|
|
@@ -868,9 +869,7 @@
|
|
| 868 |
<span class="vtv-popup-title" id="vtv-popup-title">📺 VTV Player</span>
|
| 869 |
<button class="vtv-popup-close" id="vtv-popup-close">✕</button>
|
| 870 |
</div>
|
| 871 |
-
<div class="vtv-popup-frame" id="vtv-popup-frame">
|
| 872 |
-
<div class="vtv-popup-loader" id="vtv-popup-loader"><div class="vtv-spinner"></div>Đang tải...</div>
|
| 873 |
-
</div>
|
| 874 |
`;
|
| 875 |
document.body.appendChild(popup);
|
| 876 |
document.getElementById('vtv-popup-close').onclick = closeVtvPopup;
|
|
@@ -881,14 +880,35 @@
|
|
| 881 |
if (hdr) hdr.style.display = hideHeader ? 'none' : 'flex';
|
| 882 |
document.getElementById('vtv-popup-title').textContent = title || '📺 VTV Player';
|
| 883 |
const frame = document.getElementById('vtv-popup-frame');
|
| 884 |
-
frame.innerHTML = '<div class="vtv-popup-loader" id="vtv-popup-loader"><div class="vtv-spinner"></div>Đang tải...</div>';
|
| 885 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 886 |
const iframe = document.createElement('iframe');
|
| 887 |
-
iframe.
|
| 888 |
-
iframe.
|
| 889 |
-
iframe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 890 |
frame.appendChild(iframe);
|
| 891 |
popup.classList.add('show');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 892 |
}
|
| 893 |
|
| 894 |
// Open TS token URL in popup
|
|
|
|
| 164 |
.vtv-popup-header{display:flex;align-items:center;justify-content:space-between;padding:8px 12px;background:#111;border-bottom:1px solid #333}
|
| 165 |
.vtv-popup-title{font-size:14px;font-weight:700;color:#00ccff}
|
| 166 |
.vtv-popup-close{background:#333;border:none;color:#fff;font-size:18px;width:32px;height:32px;border-radius:6px;cursor:pointer}
|
| 167 |
+
.vtv-popup-frame{flex:1;position:relative;background:#000;min-height:300px}
|
| 168 |
+
.vtv-popup-frame iframe{position:absolute;inset:0;width:100%;height:100%;border:none}
|
| 169 |
.vtv-popup-frame iframe{position:absolute;inset:0;width:100%;height:100%;border:none}
|
| 170 |
.vtv-popup-loader{display:flex;align-items:center;justify-content:center;height:280px;color:#00ccff;font-size:12px;flex-direction:column;gap:8px}
|
| 171 |
.vtv-popup-btn{background:#1a2a3a;border:1px solid #2a3a4a;color:#8ab4d8;font-size:9px;padding:3px 8px;border-radius:6px;cursor:pointer;margin-left:4px}
|
|
|
|
| 869 |
<span class="vtv-popup-title" id="vtv-popup-title">📺 VTV Player</span>
|
| 870 |
<button class="vtv-popup-close" id="vtv-popup-close">✕</button>
|
| 871 |
</div>
|
| 872 |
+
<div class="vtv-popup-frame" id="vtv-popup-frame"></div>
|
|
|
|
|
|
|
| 873 |
`;
|
| 874 |
document.body.appendChild(popup);
|
| 875 |
document.getElementById('vtv-popup-close').onclick = closeVtvPopup;
|
|
|
|
| 880 |
if (hdr) hdr.style.display = hideHeader ? 'none' : 'flex';
|
| 881 |
document.getElementById('vtv-popup-title').textContent = title || '📺 VTV Player';
|
| 882 |
const frame = document.getElementById('vtv-popup-frame');
|
|
|
|
| 883 |
|
| 884 |
+
// Show loader
|
| 885 |
+
frame.innerHTML = '<div class="vtv-popup-loader" id="vtv-popup-loader"><div class="vtv-spinner"></div>Đang tải player...</div>';
|
| 886 |
+
|
| 887 |
+
// Use iframe but handle blocked embeds gracefully
|
| 888 |
const iframe = document.createElement('iframe');
|
| 889 |
+
iframe.id = 'vtv-popup-iframe';
|
| 890 |
+
iframe.setAttribute('allowfullscreen', 'true');
|
| 891 |
+
iframe.setAttribute('webkitallowfullscreen', 'true');
|
| 892 |
+
iframe.setAttribute('mozallowfullscreen', 'true');
|
| 893 |
+
iframe.setAttribute('allow', 'autoplay; encrypted-media; fullscreen');
|
| 894 |
+
iframe.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;border:none;display:none';
|
| 895 |
+
|
| 896 |
+
// Timeout to detect blocked iframe (onload fires even for blocked, so use timeout)
|
| 897 |
+
let loaded = false;
|
| 898 |
+
iframe.onload = () => { loaded = true; const l = document.getElementById('vtv-popup-loader'); if(l) l.style.display='none'; iframe.style.display = 'block'; };
|
| 899 |
frame.appendChild(iframe);
|
| 900 |
popup.classList.add('show');
|
| 901 |
+
|
| 902 |
+
// Set src after append to ensure events fire
|
| 903 |
+
setTimeout(() => { iframe.src = popupUrl; }, 50);
|
| 904 |
+
|
| 905 |
+
// If still not loaded after 4s, fallback to new window
|
| 906 |
+
setTimeout(() => {
|
| 907 |
+
if (!loaded && popup.classList.contains('show')) {
|
| 908 |
+
window.open(popupUrl, '_blank');
|
| 909 |
+
closeVtvPopup();
|
| 910 |
+
}
|
| 911 |
+
}, 4000);
|
| 912 |
}
|
| 913 |
|
| 914 |
// Open TS token URL in popup
|