Spaces:
Running
Running
v6.3: Remove standalone mytv_section.js (integrated into yt_live.js)
Browse files- static/mytv_section.js +0 -144
static/mytv_section.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
| 1 |
-
// === VNEWS — MyTV Highlights Section ===
|
| 2 |
-
// Loaded separately to avoid breaking VTV block
|
| 3 |
-
(function(){
|
| 4 |
-
if(window._mytvLoaded) return;
|
| 5 |
-
window._mytvLoaded = true;
|
| 6 |
-
|
| 7 |
-
// Inject styles
|
| 8 |
-
const style = document.createElement('style');
|
| 9 |
-
style.textContent = ``;
|
| 10 |
-
document.head.appendChild(style);
|
| 11 |
-
|
| 12 |
-
function buildMyTVSection(){
|
| 13 |
-
const w = document.createElement('div');
|
| 14 |
-
w.className = 'mytv-section';
|
| 15 |
-
w.id = 'mytv-block';
|
| 16 |
-
w.innerHTML =
|
| 17 |
-
'<div class="mytv-head"><span class="mytv-title">🎬 MyTV Highlights</span><span class="mytv-badge">FULL TRẬN</span></div>' +
|
| 18 |
-
'<div id="mytv-grid" class="mytv-grid">' +
|
| 19 |
-
'<div class="mytv-loading"><div class="mytv-spinner"></div>Đang tải video...</div>' +
|
| 20 |
-
'</div>' +
|
| 21 |
-
'<button class="mytv-more" onclick="window._loadMoreMyTV()">Xem thêm →</button>';
|
| 22 |
-
return w;
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
async function loadMyTVVideos(){
|
| 26 |
-
const grid = document.getElementById('mytv-grid');
|
| 27 |
-
if(!grid) return;
|
| 28 |
-
try{
|
| 29 |
-
const r = await fetch('/api/mytv/videos?limit=8', {signal: AbortSignal.timeout(15000)});
|
| 30 |
-
const videos = await r.json();
|
| 31 |
-
if(!videos || !videos.length){
|
| 32 |
-
grid.innerHTML = '<div class="mytv-loading">Chưa có video</div>';
|
| 33 |
-
return;
|
| 34 |
-
}
|
| 35 |
-
let h = '';
|
| 36 |
-
videos.forEach((v, i)=>{
|
| 37 |
-
const thumb = `https://i.ytimg.com/vi/dQw4w9WgXcQ/mqdefault.jpg`; // placeholder
|
| 38 |
-
const title = esc(v.title || 'Video');
|
| 39 |
-
const duration = v.duration || '';
|
| 40 |
-
h += '<div class="mytv-item" onclick="window._playMyTVVideo(''+esc(v.url)+'',''+esc(title)+'')">' +
|
| 41 |
-
'<div class="mytv-thumb">' +
|
| 42 |
-
'<div style="width:100%;height:100%;background:linear-gradient(135deg,#1a2a1f,#0d1117);display:flex;align-items:center;justify-content:center;font-size:24px;">⚽</div>' +
|
| 43 |
-
'<div class="mytv-play">▶</div>' +
|
| 44 |
-
(duration ? '<div class="mytv-duration">'+esc(duration)+'</div>' : '') +
|
| 45 |
-
'</div>' +
|
| 46 |
-
'<div class="mytv-info">' +
|
| 47 |
-
'<div class="mytv-name">'+title+'</div>' +
|
| 48 |
-
'<div class="mytv-meta">MyTV · '+(v.type === 'full_match' ? 'Full trận' : 'Highlight')+'</div>' +
|
| 49 |
-
'</div>' +
|
| 50 |
-
'</div>';
|
| 51 |
-
});
|
| 52 |
-
grid.innerHTML = h;
|
| 53 |
-
}catch(e){
|
| 54 |
-
grid.innerHTML = '<div class="mytv-loading">Không tải được video</div>';
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
window._playMyTVVideo = function(url, title){
|
| 59 |
-
// Open video overlay
|
| 60 |
-
const overlay = document.getElementById('match-overlay');
|
| 61 |
-
const body = document.getElementById('mo-body');
|
| 62 |
-
const moTitle = document.getElementById('mo-title');
|
| 63 |
-
if(!overlay || !body) return;
|
| 64 |
-
|
| 65 |
-
moTitle.textContent = title || 'Video MyTV';
|
| 66 |
-
overlay.classList.add('active');
|
| 67 |
-
document.body.style.overflow = 'hidden';
|
| 68 |
-
body.innerHTML = '<div class="mytv-loading"><div class="mytv-spinner"></div>Đang tải video MyTV...</div>';
|
| 69 |
-
|
| 70 |
-
// Fetch video URL from our API
|
| 71 |
-
fetch('/api/video_url?url='+encodeURIComponent(url))
|
| 72 |
-
.then(r => r.json())
|
| 73 |
-
.then(v => {
|
| 74 |
-
if(v && v.src){
|
| 75 |
-
const isHLS = v.type === 'hls' || v.src.includes('.m3u8');
|
| 76 |
-
if(isHLS){
|
| 77 |
-
body.innerHTML = '<div style="position:relative;width:100%;aspect-ratio:16/9;background:#000;border-radius:8px;overflow:hidden;">' +
|
| 78 |
-
'<video id="mytv-video-player" playsinline controls autoplay style="width:100%;height:100%;object-fit:contain;" src="'+v.src+'"></video>' +
|
| 79 |
-
'</div>' +
|
| 80 |
-
'<div style="margin-top:8px;font-size:12px;color:#888;">Nguồn: MyTV.com.vn</div>';
|
| 81 |
-
// Try HLS.js if available
|
| 82 |
-
if(typeof Hls !== 'undefined' && Hls.isSupported()){
|
| 83 |
-
const video = document.getElementById('mytv-video-player');
|
| 84 |
-
if(video){
|
| 85 |
-
const hls = new Hls();
|
| 86 |
-
hls.loadSource(v.src);
|
| 87 |
-
hls.attachMedia(video);
|
| 88 |
-
}
|
| 89 |
-
}
|
| 90 |
-
} else {
|
| 91 |
-
body.innerHTML = '<div style="position:relative;width:100%;aspect-ratio:16/9;background:#000;border-radius:8px;overflow:hidden;">' +
|
| 92 |
-
'<video id="mytv-video-player" playsinline controls autoplay style="width:100%;height:100%;object-fit:contain;" src="'+v.src+'"></video>' +
|
| 93 |
-
'</div>';
|
| 94 |
-
}
|
| 95 |
-
} else {
|
| 96 |
-
body.innerHTML = '<div class="vtv-err" style="display:flex">' +
|
| 97 |
-
'<span>Không tìm thấy video. </span>' +
|
| 98 |
-
'<a href="'+esc(url)+'" target="_blank" style="color:#5cb87a;margin-left:4px;">Mở trực tiếp trên MyTV →</a>' +
|
| 99 |
-
'</div>';
|
| 100 |
-
}
|
| 101 |
-
})
|
| 102 |
-
.catch(e => {
|
| 103 |
-
body.innerHTML = '<div class="vtv-err" style="display:flex">' +
|
| 104 |
-
'<span>Lỗi tải video. </span>' +
|
| 105 |
-
'<a href="'+esc(url)+'" target="_blank" style="color:#5cb87a;margin-left:4px;">Mở trực tiếp trên MyTV →</a>' +
|
| 106 |
-
'</div>';
|
| 107 |
-
});
|
| 108 |
-
};
|
| 109 |
-
|
| 110 |
-
window._loadMoreMyTV = function(){
|
| 111 |
-
// Load more videos or refresh
|
| 112 |
-
const grid = document.getElementById('mytv-grid');
|
| 113 |
-
if(grid) grid.innerHTML = '<div class="mytv-loading"><div class="mytv-spinner"></div>Đang tải...</div>';
|
| 114 |
-
loadMyTVVideos();
|
| 115 |
-
};
|
| 116 |
-
|
| 117 |
-
// Auto-inject after VTV block
|
| 118 |
-
function injectMyTV(){
|
| 119 |
-
try{
|
| 120 |
-
const vtvBlock = document.getElementById('vtv-block');
|
| 121 |
-
if(vtvBlock && !document.getElementById('mytv-block')){
|
| 122 |
-
vtvBlock.insertAdjacentElement('afterend', buildMyTVSection());
|
| 123 |
-
loadMyTVVideos().catch(()=>{});
|
| 124 |
-
}
|
| 125 |
-
}catch(e){ console.warn('MyTV inject error:', e); }
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
// Try immediately, then retry after delays
|
| 129 |
-
setTimeout(injectMyTV, 1000);
|
| 130 |
-
setTimeout(injectMyTV, 3000);
|
| 131 |
-
setTimeout(injectMyTV, 6000);
|
| 132 |
-
|
| 133 |
-
// Also hook into loadHome
|
| 134 |
-
const _origLoadHome = window.loadHome;
|
| 135 |
-
if(_origLoadHome && !_origLoadHome.__mytvWrapped){
|
| 136 |
-
window.loadHome = async function(){
|
| 137 |
-
const r = await _origLoadHome.apply(this, arguments);
|
| 138 |
-
setTimeout(injectMyTV, 500);
|
| 139 |
-
setTimeout(injectMyTV, 2000);
|
| 140 |
-
return r;
|
| 141 |
-
};
|
| 142 |
-
window.loadHome.__mytvWrapped = true;
|
| 143 |
-
}
|
| 144 |
-
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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