Spaces:
Running
Running
Upload static/vtv_init.js
Browse files- static/vtv_init.js +255 -0
static/vtv_init.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ===== VNEWS VTV Player v11 — SV2 iframe + HLS.js native player toggle =====
|
| 2 |
+
(function() {
|
| 3 |
+
if (window._vtvInitLoaded) return;
|
| 4 |
+
window._vtvInitLoaded = true;
|
| 5 |
+
|
| 6 |
+
var CHANNELS = [
|
| 7 |
+
{id:'vtv1',name:'VTV1',badge:'Tin tức'},{id:'vtv2',name:'VTV2',badge:'Khoa học'},
|
| 8 |
+
{id:'vtv3',name:'VTV3',badge:'Giải trí'},{id:'vtv4',name:'VTV4',badge:'Quốc Tế'},
|
| 9 |
+
{id:'vtv5',name:'VTV5',badge:'Miền Nam'},{id:'vtv6',name:'VTV6',badge:'Thanh Niên'},
|
| 10 |
+
{id:'vtv7',name:'VTV7',badge:'Giáo Dục'},{id:'vtv8',name:'VTV8',badge:'Miền Trung'},
|
| 11 |
+
{id:'vtv9',name:'VTV9',badge:'Miền Bắc'},{id:'vtv10',name:'VTV10',badge:'Cần Thơ'},
|
| 12 |
+
{id:'vtvprime',name:'VTVPrime',badge:'Prime'},
|
| 13 |
+
];
|
| 14 |
+
|
| 15 |
+
var _currentCh = null;
|
| 16 |
+
var _epgTimer = null;
|
| 17 |
+
var _epgData = [];
|
| 18 |
+
var _timeTimer = null;
|
| 19 |
+
var _serverDate = '';
|
| 20 |
+
var _nativeMode = false;
|
| 21 |
+
var _hls = null;
|
| 22 |
+
|
| 23 |
+
(function injectCSS() {
|
| 24 |
+
if (document.getElementById('vtv-pro-css')) return;
|
| 25 |
+
var s = document.createElement('style');
|
| 26 |
+
s.id = 'vtv-pro-css';
|
| 27 |
+
s.textContent = [
|
| 28 |
+
'#vtv-player-section{display:block!important;margin:8px 0 10px;background:linear-gradient(180deg,#0a0e17,#111622);border:1px solid rgba(0,150,255,.15);border-radius:14px;overflow:hidden}',
|
| 29 |
+
'#vtv-player-section .vtv-pro-head{display:flex;align-items:center;gap:10px;padding:10px 14px;background:linear-gradient(90deg,#0a1628,rgba(0,102,204,.08))}',
|
| 30 |
+
'#vtv-player-section .vtv-pro-logo{width:22px;height:22px;border-radius:50%;background:linear-gradient(135deg,#0066cc,#00ccff);display:flex;align-items:center;justify-content:center;font-size:11px;color:#fff;font-weight:800;flex-shrink:0}',
|
| 31 |
+
'#vtv-player-section .vtv-pro-title{font-size:13px;font-weight:700;color:#e8eaed}',
|
| 32 |
+
'#vtv-player-section .vtv-pro-live{font-size:9px;font-weight:700;color:#00cc88;background:rgba(0,204,136,.12);padding:2px 8px;border-radius:10px;display:flex;align-items:center;gap:4px;margin-left:auto}',
|
| 33 |
+
'#vtv-player-section .vtv-pro-live-dot{width:5px;height:5px;border-radius:50%;background:#00cc88;animation:vtv-pro-pulse 1.2s infinite}',
|
| 34 |
+
'@keyframes vtv-pro-pulse{0%,100%{opacity:1}50%{opacity:.3}}',
|
| 35 |
+
'#vtv-player-section .vtv-pro-tabs{display:flex;flex-wrap:wrap;gap:2px;padding:6px 10px 8px;overflow-x:auto;scrollbar-width:none}',
|
| 36 |
+
'#vtv-player-section .vtv-pro-tab{padding:5px 10px;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.06);border-radius:8px;color:#9aa0a6;font-size:10px;cursor:pointer;white-space:nowrap;flex-shrink:0}',
|
| 37 |
+
'#vtv-player-section .vtv-pro-tab.on{background:rgba(0,102,204,.2);border-color:#0066cc;color:#fff;font-weight:600}',
|
| 38 |
+
'#vtv-player-section .vtv-pro-tab .b{font-size:7px;opacity:.5;display:block;margin-top:1px}',
|
| 39 |
+
'#vtv-player-section .vtv-pro-frame{position:relative;width:100%;aspect-ratio:16/9;background:#000;min-height:200px}',
|
| 40 |
+
'#vtv-player-section .vtv-pro-frame iframe{position:absolute;inset:0;width:100%!important;height:100%!important;border:none;background:#000}',
|
| 41 |
+
'#vtv-player-section .vtv-pro-frame video{position:absolute;inset:0;width:100%;height:100%;background:#000}',
|
| 42 |
+
'#vtv-player-section .vtv-pro-load{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;min-height:200px;gap:12px;color:#9aa0a6}',
|
| 43 |
+
'#vtv-player-section .vtv-pro-spinner{width:28px;height:28px;border:2px solid rgba(255,255,255,.06);border-top-color:#0066cc;border-radius:50%;animation:vtv-pro-spin .7s linear infinite}',
|
| 44 |
+
'@keyframes vtv-pro-spin{to{transform:rotate(360deg)}}',
|
| 45 |
+
'#vtv-player-section .vtv-pro-err{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;min-height:200px;gap:10px;color:#9aa0a6;text-align:center;padding:20px}',
|
| 46 |
+
'#vtv-player-section .vtv-pro-err .icon{font-size:28px;opacity:.5}',
|
| 47 |
+
'#vtv-player-section .vtv-pro-err button{background:rgba(0,102,204,.15);border:1px solid rgba(0,102,204,.3);color:#8ab4f8;padding:7px 16px;border-radius:8px;font-size:11px;cursor:pointer}',
|
| 48 |
+
'#vtv-player-section .vtv-pro-controls{display:flex;align-items:center;gap:6px;padding:6px 12px;background:rgba(0,0,0,.3)}',
|
| 49 |
+
'#vtv-player-section .vtv-pro-btn{background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.08);color:#9aa0a6;font-size:10px;padding:4px 10px;border-radius:6px;cursor:pointer}',
|
| 50 |
+
'#vtv-player-section .vtv-pro-switch{font-size:9px;padding:3px 8px;background:rgba(0,150,255,.08);border:1px solid rgba(0,150,255,.2);color:#8ab4f8;border-radius:6px;cursor:pointer;white-space:nowrap}',
|
| 51 |
+
'#vtv-player-section .vtv-pro-switch.active{background:rgba(0,204,136,.12);border-color:rgba(0,204,136,.3);color:#00cc88}',
|
| 52 |
+
'#vtv-player-section .vtv-pro-epg{border-top:1px solid rgba(255,255,255,.04);background:rgba(0,0,0,.15)}',
|
| 53 |
+
'#vtv-player-section .vtv-pro-epg-hdr{display:flex;align-items:center;justify-content:space-between;padding:8px 12px 4px}',
|
| 54 |
+
'#vtv-player-section .vtv-pro-epg-title{font-size:10px;font-weight:600;color:#9aa0a6;text-transform:uppercase}',
|
| 55 |
+
'#vtv-player-section .vtv-pro-epg-time{font-size:9px;color:#5f6368}',
|
| 56 |
+
'#vtv-player-section .vtv-pro-epg-list{padding:2px 8px 10px;display:flex;flex-direction:column;gap:2px;max-height:200px;overflow-y:auto}',
|
| 57 |
+
'#vtv-player-section .vtv-pro-epg-row{display:flex;align-items:center;gap:8px;padding:5px 8px;border-radius:6px;border-left:2px solid transparent;font-size:11px}',
|
| 58 |
+
'#vtv-player-section .vtv-pro-epg-row.now{border-left-color:#00cc88;background:rgba(0,204,136,.06)}',
|
| 59 |
+
'#vtv-player-section .vtv-pro-epg-row.passed{opacity:.35}',
|
| 60 |
+
'#vtv-player-section .vtv-pro-epg-row .t{font-size:10px;color:#5f6368;min-width:38px}',
|
| 61 |
+
'#vtv-player-section .vtv-pro-epg-row.now .t{color:#00cc88;font-weight:600}',
|
| 62 |
+
'#vtv-player-section .vtv-pro-epg-row .n{color:#e8eaed}',
|
| 63 |
+
'#vtv-player-section .vtv-pro-epg-row.now .n{color:#fff;font-weight:500}',
|
| 64 |
+
'#vtv-player-section .vtv-pro-epg-empty{color:#5f6368;font-size:11px;padding:12px 14px;text-align:center}',
|
| 65 |
+
].join('');
|
| 66 |
+
document.head.appendChild(s);
|
| 67 |
+
})();
|
| 68 |
+
|
| 69 |
+
function getVNTime() {
|
| 70 |
+
var now = new Date();
|
| 71 |
+
try {
|
| 72 |
+
var opts = { timeZone: 'Asia/Ho_Chi_Minh', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, year: 'numeric', month: '2-digit', day: '2-digit' };
|
| 73 |
+
var parts = new Intl.DateTimeFormat('en-CA', opts).formatToParts(now);
|
| 74 |
+
var hh=0,mm=0,ss=0,yy=2026,mo=1,dd=1;
|
| 75 |
+
for (var i = 0; i < parts.length; i++) {
|
| 76 |
+
var p = parts[i];
|
| 77 |
+
if (p.type === 'hour') hh = parseInt(p.value);
|
| 78 |
+
else if (p.type === 'minute') mm = parseInt(p.value);
|
| 79 |
+
else if (p.type === 'second') ss = parseInt(p.value);
|
| 80 |
+
else if (p.type === 'year') yy = parseInt(p.value);
|
| 81 |
+
else if (p.type === 'month') mo = parseInt(p.value);
|
| 82 |
+
else if (p.type === 'day') dd = parseInt(p.value);
|
| 83 |
+
}
|
| 84 |
+
return new Date(yy, mo - 1, dd, hh, mm, ss);
|
| 85 |
+
} catch(e) {
|
| 86 |
+
var utc = new Date(now.getTime() + now.getTimezoneOffset() * 60000);
|
| 87 |
+
return new Date(utc.getTime() + 7 * 3600000);
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
function formatTime(d) { return (d.getHours()<10?'0':'')+d.getHours()+':'+(d.getMinutes()<10?'0':'')+d.getMinutes(); }
|
| 92 |
+
|
| 93 |
+
function loadEPG(chId) {
|
| 94 |
+
var epgEl = document.getElementById('vtv-pro-epg-body');
|
| 95 |
+
if (!epgEl) return;
|
| 96 |
+
epgEl.innerHTML = '<div class="vtv-pro-epg-load"><div class="vtv-pro-spinner" style="width:12px;height:12px;border-width:1.5px"></div>Đang tải lịch...</div>';
|
| 97 |
+
var xhr = new XMLHttpRequest();
|
| 98 |
+
xhr.open('GET', '/api/vtv/epg/' + chId, true);
|
| 99 |
+
xhr.timeout = 15000;
|
| 100 |
+
xhr.onload = function() {
|
| 101 |
+
try {
|
| 102 |
+
var data = JSON.parse(xhr.responseText);
|
| 103 |
+
_serverDate = data.date || '';
|
| 104 |
+
_epgData = data.programs || [];
|
| 105 |
+
renderEPG();
|
| 106 |
+
} catch(e) { epgEl.innerHTML = '<div class="vtv-pro-epg-empty">Không có lịch phát sóng</div>'; }
|
| 107 |
+
};
|
| 108 |
+
xhr.onerror = xhr.ontimeout = function() { epgEl.innerHTML = '<div class="vtv-pro-epg-empty">Không tải được lịch</div>'; };
|
| 109 |
+
xhr.send();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
function renderEPG() {
|
| 113 |
+
var epgEl = document.getElementById('vtv-pro-epg-body');
|
| 114 |
+
if (!epgEl || !_epgData || !_epgData.length) {
|
| 115 |
+
if (epgEl) epgEl.innerHTML = '<div class="vtv-pro-epg-empty">Chưa có lịch phát sóng</div>';
|
| 116 |
+
return;
|
| 117 |
+
}
|
| 118 |
+
var vnNow = getVNTime();
|
| 119 |
+
var nowStr = formatTime(vnNow);
|
| 120 |
+
_epgData.sort(function(a,b) { return a.time.localeCompare(b.time); });
|
| 121 |
+
for (var i = 0; i < _epgData.length; i++) {
|
| 122 |
+
_epgData[i].now = false;
|
| 123 |
+
var p = _epgData[i], nxt = _epgData[i + 1];
|
| 124 |
+
if (p.time <= nowStr && (!nxt || nxt.time > nowStr)) { p.now = true; p.end_time = nxt ? nxt.time : ''; }
|
| 125 |
+
}
|
| 126 |
+
var html = '';
|
| 127 |
+
for (var i = 0; i < _epgData.length; i++) {
|
| 128 |
+
var p = _epgData[i];
|
| 129 |
+
var cls = 'vtv-pro-epg-row' + (p.now ? ' now' : '') + (p.time < nowStr ? ' passed' : '');
|
| 130 |
+
var xt = p.end_time ? ' → ' + p.end_time : (i < _epgData.length - 1 ? ' → ' + _epgData[i+1].time : '');
|
| 131 |
+
html += '<div class="' + cls + '"><span class="t">' + p.time + xt + '</span><span class="n">' + p.title + '</span></div>';
|
| 132 |
+
}
|
| 133 |
+
epgEl.innerHTML = html;
|
| 134 |
+
var nowEl = epgEl.querySelector('.now');
|
| 135 |
+
if (nowEl) nowEl.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function destroyHLS() { if (_hls) { try { _hls.destroy(); } catch(e){} _hls = null; } }
|
| 139 |
+
|
| 140 |
+
function playNativeHLS(chId, m3u8ProxyUrl) {
|
| 141 |
+
destroyHLS();
|
| 142 |
+
var frame = document.getElementById('vtv-pro-frame');
|
| 143 |
+
if (!frame) return;
|
| 144 |
+
frame.innerHTML = '<video id="vtv-native-video" controls autoplay playsinline style="position:absolute;inset:0;width:100%;height:100%;background:#000"></video>';
|
| 145 |
+
var video = document.getElementById('vtv-native-video');
|
| 146 |
+
if (!video) return;
|
| 147 |
+
if (typeof Hls !== 'undefined' && Hls.isSupported()) {
|
| 148 |
+
_hls = new Hls({ enableWorker: false });
|
| 149 |
+
_hls.loadSource(m3u8ProxyUrl);
|
| 150 |
+
_hls.attachMedia(video);
|
| 151 |
+
_hls.on(Hls.Events.MANIFEST_PARSED, function() { video.play().catch(function(){}); });
|
| 152 |
+
_hls.on(Hls.Events.ERROR, function(evt, data) {
|
| 153 |
+
if (data.fatal) { destroyHLS(); video.src = m3u8ProxyUrl; video.play().catch(function(){}); }
|
| 154 |
+
});
|
| 155 |
+
} else { video.src = m3u8ProxyUrl; }
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
window._vtvToggleNative = function(btn) {
|
| 159 |
+
if (!_currentCh) return;
|
| 160 |
+
_nativeMode = !_nativeMode;
|
| 161 |
+
btn.classList.toggle('active', _nativeMode);
|
| 162 |
+
btn.innerHTML = _nativeMode ? '📡 HLS' : '🔌 JWPlayer';
|
| 163 |
+
var frame = document.getElementById('vtv-pro-frame');
|
| 164 |
+
if (!frame) return;
|
| 165 |
+
var xhr = new XMLHttpRequest();
|
| 166 |
+
xhr.open('GET', '/api/vtv/stream/' + _currentCh, true);
|
| 167 |
+
xhr.timeout = 15000;
|
| 168 |
+
xhr.onload = function() {
|
| 169 |
+
try {
|
| 170 |
+
var data = JSON.parse(xhr.responseText);
|
| 171 |
+
if (_nativeMode) {
|
| 172 |
+
var m3u8Url = data.m3u8_proxy_url || data.proxy_url_hls || data.stream_url;
|
| 173 |
+
if (m3u8Url) { playNativeHLS(_currentCh, m3u8Url); }
|
| 174 |
+
else { frame.innerHTML = '<div class="vtv-pro-err"><div class="icon">📡</div><div class="msg">Kênh không hỗ trợ HLS</div></div>'; _nativeMode = false; btn.classList.remove('active'); btn.innerHTML = '🔌 JWPlayer'; }
|
| 175 |
+
} else {
|
| 176 |
+
var iframeUrl = data.iframe_url;
|
| 177 |
+
if (iframeUrl) {
|
| 178 |
+
destroyHLS();
|
| 179 |
+
var iframe = document.createElement('iframe');
|
| 180 |
+
iframe.src = iframeUrl; iframe.setAttribute('allowfullscreen', 'true'); iframe.setAttribute('allow', 'autoplay; encrypted-media; fullscreen');
|
| 181 |
+
iframe.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;border:none;background:#000';
|
| 182 |
+
frame.innerHTML = ''; frame.appendChild(iframe);
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
} catch(e) { frame.innerHTML = '<div class="vtv-pro-err"><div class="icon">⚠️</div></div>'; }
|
| 186 |
+
};
|
| 187 |
+
xhr.onerror = function() { frame.innerHTML = '<div class="vtv-pro-err"><div class="icon">🔌</div><div class="msg">Lỗi kết nối</div></div>'; };
|
| 188 |
+
xhr.send();
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
window._vtvProSwitch = function(chId) {
|
| 192 |
+
_currentCh = chId; _nativeMode = false;
|
| 193 |
+
var tabs = document.querySelectorAll('#vtv-player-section .vtv-pro-tab');
|
| 194 |
+
for (var i = 0; i < tabs.length; i++) tabs[i].className = 'vtv-pro-tab' + (tabs[i].getAttribute('data-ch') === chId ? ' on' : '');
|
| 195 |
+
var toggleBtn = document.getElementById('vtv-pro-toggle-btn');
|
| 196 |
+
if (toggleBtn) { toggleBtn.classList.remove('active'); toggleBtn.innerHTML = '🔌 JWPlayer'; }
|
| 197 |
+
var timeEl = document.getElementById('vtv-pro-time');
|
| 198 |
+
if (timeEl) timeEl.textContent = formatTime(getVNTime()) + ' GMT+7' + (_serverDate ? ' - ' + _serverDate : '');
|
| 199 |
+
destroyHLS();
|
| 200 |
+
var frame = document.getElementById('vtv-pro-frame');
|
| 201 |
+
if (!frame) return;
|
| 202 |
+
frame.innerHTML = '<div class="vtv-pro-load"><div class="vtv-pro-spinner"></div><span>Đang kết nối ' + chId.toUpperCase() + '...</span></div>';
|
| 203 |
+
loadEPG(chId);
|
| 204 |
+
if (_epgTimer) clearInterval(_epgTimer);
|
| 205 |
+
_epgTimer = setInterval(function() { if (_currentCh) loadEPG(_currentCh); }, 60000);
|
| 206 |
+
var xhr = new XMLHttpRequest();
|
| 207 |
+
xhr.open('GET', '/api/vtv/stream/' + chId, true);
|
| 208 |
+
xhr.timeout = 15000;
|
| 209 |
+
xhr.onload = function() {
|
| 210 |
+
try {
|
| 211 |
+
var data = JSON.parse(xhr.responseText);
|
| 212 |
+
var iframeUrl = data.iframe_url;
|
| 213 |
+
if (!iframeUrl) { frame.innerHTML = '<div class="vtv-pro-err"><div class="icon">📡</div><div class="msg">Kênh không khả dụng</div><button onclick="_vtvProSwitch(\''+chId+'\')">Thử lại</button></div>'; return; }
|
| 214 |
+
var iframe = document.createElement('iframe');
|
| 215 |
+
iframe.src = iframeUrl; iframe.setAttribute('allowfullscreen', 'true'); iframe.setAttribute('allow', 'autoplay; encrypted-media; fullscreen');
|
| 216 |
+
iframe.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;border:none;background:#000';
|
| 217 |
+
frame.innerHTML = ''; frame.appendChild(iframe);
|
| 218 |
+
} catch(e) { frame.innerHTML = '<div class="vtv-pro-err"><div class="icon">⚠️</div></div>'; }
|
| 219 |
+
};
|
| 220 |
+
xhr.onerror = xhr.ontimeout = function() { frame.innerHTML = '<div class="vtv-pro-err"><div class="icon">🔌</div><div class="msg">Mất kết nối máy chủ</div><button onclick="_vtvProSwitch(\''+chId+'\')">Thử lại</button></div>'; };
|
| 221 |
+
xhr.send();
|
| 222 |
+
};
|
| 223 |
+
|
| 224 |
+
function buildHTML() {
|
| 225 |
+
var tabs = '';
|
| 226 |
+
for (var i = 0; i < CHANNELS.length; i++) {
|
| 227 |
+
var ch = CHANNELS[i];
|
| 228 |
+
tabs += '<span class="vtv-pro-tab" data-ch="'+ch.id+'" onclick="_vtvProSwitch(\''+ch.id+'\')">' + ch.name + '<span class="b">'+ch.badge+'</span></span>';
|
| 229 |
+
}
|
| 230 |
+
return '<div id="vtv-player-section"><div class="vtv-pro-head"><div class="vtv-pro-logo">V</div><span class="vtv-pro-title">VTV Player</span><span class="vtv-pro-live"><span class="vtv-pro-live-dot"></span>TRỰC TIẾP</span></div><div class="vtv-pro-tabs">'+tabs+'</div><div class="vtv-pro-frame" id="vtv-pro-frame"><div class="vtv-pro-load"><div class="vtv-pro-spinner"></div><span>Chọn kênh để xem trực tiếp</span></div></div><div class="vtv-pro-controls"><span id="vtv-pro-time" class="vtv-pro-btn" style="background:none;border:none;font-size:10px;color:#5f6368;margin-right:auto"></span><span class="vtv-pro-switch" id="vtv-pro-toggle-btn" onclick="_vtvToggleNative(this)">🔌 JWPlayer</span></div><div class="vtv-pro-epg"><div class="vtv-pro-epg-hdr"><span class="vtv-pro-epg-title">Lịch phát sóng — nguồn VTV.vn</span></div><div class="vtv-pro-epg-list" id="vtv-pro-epg-body"><div class="vtv-pro-epg-empty">Chọn kênh để xem lịch phát sóng</div></div></div></div>';
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
function inject() {
|
| 234 |
+
var homeEl = document.getElementById('view-home');
|
| 235 |
+
if (!homeEl || document.getElementById('vtv-player-section')) return;
|
| 236 |
+
var featured = document.getElementById('home-featured-area') || homeEl.querySelector('.featured-match, .fm-section, .slider-wrap');
|
| 237 |
+
if (featured && featured.parentNode) featured.insertAdjacentHTML('afterend', buildHTML());
|
| 238 |
+
else if (homeEl.firstChild) homeEl.insertAdjacentHTML('afterbegin', buildHTML());
|
| 239 |
+
setTimeout(function() { if (window._vtvProSwitch) window._vtvProSwitch('vtv6'); }, 500);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
var orig = window.loadHome;
|
| 243 |
+
if (typeof orig === 'function') {
|
| 244 |
+
window.loadHome = function() {
|
| 245 |
+
var r = orig.apply(this, arguments);
|
| 246 |
+
if (r && typeof r.then === 'function') return r.then(function(v) { setTimeout(inject, 2000); return v; });
|
| 247 |
+
else { setTimeout(inject, 2000); return r; }
|
| 248 |
+
};
|
| 249 |
+
} else {
|
| 250 |
+
(function waitAndInject() {
|
| 251 |
+
if (document.getElementById('view-home') && !document.getElementById('vtv-player-section')) inject();
|
| 252 |
+
else if (!document.getElementById('vtv-player-section')) setTimeout(waitAndInject, 1000);
|
| 253 |
+
})();
|
| 254 |
+
}
|
| 255 |
+
})();
|