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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// === VNEWS — Match Detail UI ===
|
| 2 |
+
// Fetches & renders match detail (preview, lineups, H2H, overlay stats) from bongda.com.vn
|
| 3 |
+
// Loaded after app_v2.js; extends the match overlay with a "Chi tiết" tab.
|
| 4 |
+
|
| 5 |
+
(function(){
|
| 6 |
+
// Inject styles
|
| 7 |
+
if(document.getElementById('match-detail-css')) return;
|
| 8 |
+
const s = document.createElement('style');
|
| 9 |
+
s.id = 'match-detail-css';
|
| 10 |
+
s.textContent = `
|
| 11 |
+
.mo-tab-detail {
|
| 12 |
+
|
| 13 |
+
}
|
| 14 |
+
.md-loading{display:flex;align-items:center;justify-content:center;padding:30px;color:#888;font-size:12px}
|
| 15 |
+
.md-section{margin-bottom:16px}
|
| 16 |
+
.md-section-title{font-size:13px;font-weight:800;color:#5cb87a;margin-bottom:8px;padding-bottom:4px;border-bottom:1px solid #2a2a2a;display:flex;align-items:center;gap:6px}
|
| 17 |
+
.md-preview-text{font-size:13px;color:#ccc;line-height:1.6;white-space:pre-wrap;background:#1a1a1a;border-radius:8px;padding:12px;border-left:3px solid #2d8659}
|
| 18 |
+
.md-lineups{display:grid;grid-template-columns:1fr 1fr;gap:12px}
|
| 19 |
+
.md-team-box{background:#1a2a1f;border:1px solid #2a3a2a;border-radius:8px;padding:10px}
|
| 20 |
+
.md-team-name{font-size:13px;font-weight:800;color:#5cb87a;margin-bottom:4px;text-align:center}
|
| 21 |
+
.md-formation{font-size:10px;color:#888;text-align:center;margin-bottom:8px}
|
| 22 |
+
.md-player-list{list-style:none;padding:0;margin:0}
|
| 23 |
+
.md-player-item{font-size:11px;color:#ccc;padding:3px 0;border-bottom:1px solid #1a2a1f;display:flex;align-items:center;gap:6px}
|
| 24 |
+
.md-player-no{width:18px;height:18px;border-radius:50%;background:#2d8659;color:#fff;font-size:9px;font-weight:700;display:flex;align-items:center;justify-content:center;flex:0 0 18px}
|
| 25 |
+
.md-subs-title{font-size:11px;color:#888;margin-top:8px;margin-bottom:4px;font-style:italic}
|
| 26 |
+
.md-h2h-item{display:flex;align-items:center;gap:8px;padding:8px;background:#1a1a1a;border-radius:6px;margin-bottom:4px}
|
| 27 |
+
.md-h2h-date{font-size:10px;color:#888;min-width:60px}
|
| 28 |
+
.md-h2h-teams{flex:1;display:flex;align-items:center;gap:6px;font-size:11px;color:#ddd}
|
| 29 |
+
.md-h2h-home{text-align:right;flex:1}
|
| 30 |
+
.md-h2h-away{text-align:left;flex:1}
|
| 31 |
+
.md-h2h-score{font-size:13px;font-weight:800;color:#f0c040;min-width:40px;text-align:center}
|
| 32 |
+
.md-h2h-live{color:#e74c3c;font-size:9px;font-weight:700}
|
| 33 |
+
.md-no-data{color:#777;font-size:12px;padding:20px;text-align:center}
|
| 34 |
+
`;
|
| 35 |
+
document.head.appendChild(s);
|
| 36 |
+
|
| 37 |
+
// Store original loadMatchTab
|
| 38 |
+
const _origLoadMatchTab = window.loadMatchTab;
|
| 39 |
+
|
| 40 |
+
// Override loadMatchTab to handle detail tab
|
| 41 |
+
window.loadMatchTab = async function(tab){
|
| 42 |
+
if(tab === 'detail'){
|
| 43 |
+
// Activate detail tab UI
|
| 44 |
+
document.querySelectorAll('.mo-tab').forEach(t=>t.classList.remove('active'));
|
| 45 |
+
document.querySelectorAll('.mo-tab').forEach(t=>{
|
| 46 |
+
if(t.textContent.includes('Chi tiết') || t.textContent.includes('Detail')) t.classList.add('active');
|
| 47 |
+
});
|
| 48 |
+
const el = document.getElementById('mo-body');
|
| 49 |
+
if(!el) return;
|
| 50 |
+
el.innerHTML = '<div class="md-loading">⏳ Đang tải chi tiết trận đấu...</div>';
|
| 51 |
+
try{
|
| 52 |
+
const eventId = window._currentEventId;
|
| 53 |
+
if(!eventId){ el.innerHTML = '<div class="md-no-data">Không tìm thấy mã trận đấu</div>'; return; }
|
| 54 |
+
const r = await fetch(`/api/match/${eventId}/detail`);
|
| 55 |
+
const d = await r.json();
|
| 56 |
+
renderMatchDetail(el, d);
|
| 57 |
+
}catch(e){
|
| 58 |
+
el.innerHTML = '<div class="md-no-data">Lỗi tải chi tiết: ' + esc(e.message) + '</div>';
|
| 59 |
+
}
|
| 60 |
+
} else {
|
| 61 |
+
// Call original for comm/stats tabs
|
| 62 |
+
_origLoadMatchTab(tab);
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
function renderMatchDetail(el, data){
|
| 67 |
+
let h = '';
|
| 68 |
+
|
| 69 |
+
// === 1. Preview / Commentaries ===
|
| 70 |
+
if(data.commentaries_html && data.commentaries_html.length > 10){
|
| 71 |
+
h += '<div class="md-section">';
|
| 72 |
+
h += '<div class="md-section-title">📋 Thông tin trận đấu</div>';
|
| 73 |
+
// Clean up the HTML - remove ads, scripts, iframes
|
| 74 |
+
let cleanHtml = data.commentaries_html
|
| 75 |
+
.replace(/<script[^>]*>.*?<\/script>/gi, '')
|
| 76 |
+
.replace(/<iframe[^>]*>.*?<\/iframe>/gi, '')
|
| 77 |
+
.replace(/<ins[^>]*>.*?<\/ins>/gi, '')
|
| 78 |
+
.replace(/style="[^"]*display:\s*none[^"]*"/gi, 'style="display:none"');
|
| 79 |
+
h += '<div class="md-preview-container">' + cleanHtml + '</div>';
|
| 80 |
+
h += '</div>';
|
| 81 |
+
} else if(data.preview_text && data.preview_text.length > 0){
|
| 82 |
+
h += '<div class="md-section">';
|
| 83 |
+
h += '<div class="md-section-title">📋 Thông tin trận đấu</div>';
|
| 84 |
+
h += '<div class="md-preview-text">' + data.preview_text.map(t=>esc(t)).join('\n\n') + '</div>';
|
| 85 |
+
h += '</div>';
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// === 2. Lineups ===
|
| 89 |
+
if(data.lineups_html && data.lineups_html.length > 10){
|
| 90 |
+
h += '<div class="md-section">';
|
| 91 |
+
h += '<div class="md-section-title">⚽ Đội hình</div>';
|
| 92 |
+
let cleanLineups = data.lineups_html
|
| 93 |
+
.replace(/<script[^>]*>.*?<\/script>/gi, '')
|
| 94 |
+
.replace(/<iframe[^>]*>.*?<\/iframe>/gi, '')
|
| 95 |
+
.replace(/<ins[^>]*>.*?<\/ins>/gi, '');
|
| 96 |
+
h += '<div class="md-lineups-container">' + cleanLineups + '</div>';
|
| 97 |
+
h += '</div>';
|
| 98 |
+
} else if(data.lineups && (data.lineups.home_players || data.lineups.away_players)){
|
| 99 |
+
h += '<div class="md-section">';
|
| 100 |
+
h += '<div class="md-section-title">⚽ Đội hình</div>';
|
| 101 |
+
h += renderLineups(data.lineups);
|
| 102 |
+
h += '</div>';
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// === 3. Head-to-Head ===
|
| 106 |
+
if(data.h2h_html && data.h2h_html.length > 10){
|
| 107 |
+
h += '<div class="md-section">';
|
| 108 |
+
h += '<div class="md-section-title">🔄 Đối đầu (H2H)</div>';
|
| 109 |
+
let cleanH2h = data.h2h_html
|
| 110 |
+
.replace(/<script[^>]*>.*?<\/script>/gi, '')
|
| 111 |
+
.replace(/<iframe[^>]*>.*?<\/iframe>/gi, '');
|
| 112 |
+
h += '<div class="md-h2h-container">' + cleanH2h + '</div>';
|
| 113 |
+
h += '</div>';
|
| 114 |
+
} else if(data.h2h && data.h2h.length > 0){
|
| 115 |
+
h += '<div class="md-section">';
|
| 116 |
+
h += '<div class="md-section-title">🔄 Đối đầu (H2H)</div>';
|
| 117 |
+
h += renderH2H(data.h2h);
|
| 118 |
+
h += '</div>';
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// === 4. Match Stats ===
|
| 122 |
+
if(data.stats_html && data.stats_html.length > 10){
|
| 123 |
+
h += '<div class="md-section">';
|
| 124 |
+
h += '<div class="md-section-title">📊 Thống kê</div>';
|
| 125 |
+
let cleanStats = data.stats_html
|
| 126 |
+
.replace(/<script[^>]*>.*?<\/script>/gi, '')
|
| 127 |
+
.replace(/<iframe[^>]*>.*?<\/iframe>/gi, '');
|
| 128 |
+
h += '<div class="md-stats-container">' + cleanStats + '</div>';
|
| 129 |
+
h += '</div>';
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
// === 5. Match Info ===
|
| 133 |
+
if(data.info && Object.keys(data.info).length > 0){
|
| 134 |
+
h += '<div class="md-section">';
|
| 135 |
+
h += '<div class="md-section-title">📍 Thông tin</div>';
|
| 136 |
+
h += '<div style="font-size:12px;color:#ccc;line-height:1.8;padding:8px;background:#1a1a1a;border-radius:8px">';
|
| 137 |
+
if(data.info.date) h += '<div>📅 Ngày: <b>' + esc(data.info.date) + '</b></div>';
|
| 138 |
+
if(data.info.time) h += '<div>🕐 Giờ: <b>' + esc(data.info.time) + '</b></div>';
|
| 139 |
+
if(data.info.stadium) h += '<div>🏟 Sân: <b>' + esc(data.info.stadium) + '</b></div>';
|
| 140 |
+
if(data.info.referee) h += '<div>👨⚖️ Trọng tài: <b>' + esc(data.info.referee) + '</b></div>';
|
| 141 |
+
h += '</div></div>';
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
if(!h){
|
| 145 |
+
h = '<div class="md-no-data">Chưa có chi tiết cho trận đấu này.<br><small style="color:#666">Dữ liệu sẽ cập nhật khi giải khởi tranh.</small></div>';
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
el.innerHTML = h;
|
| 149 |
+
// Prevent link navigation inside overlay
|
| 150 |
+
el.querySelectorAll('a').forEach(a=>a.addEventListener('click', e=>e.preventDefault()));
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
function renderLineups(lineups){
|
| 154 |
+
let h = '<div class="md-lineups">';
|
| 155 |
+
// Home team
|
| 156 |
+
h += '<div class="md-team-box">';
|
| 157 |
+
h += '<div class="md-team-name">' + esc(lineups.home_team || 'Đội nhà') + '</div>';
|
| 158 |
+
if(lineups.home_formation) h += '<div class="md-formation">Đội hình: ' + esc(lineups.home_formation) + '</div>';
|
| 159 |
+
h += '<ul class="md-player-list">';
|
| 160 |
+
(lineups.home_players || []).forEach((p,i)=>{
|
| 161 |
+
h += '<li class="md-player-item"><span class="md-player-no">' + (i+1) + '</span>' + esc(p) + '</li>';
|
| 162 |
+
});
|
| 163 |
+
h += '</ul>';
|
| 164 |
+
if(lineups.home_subs && lineups.home_subs.length > 0){
|
| 165 |
+
h += '<div class="md-subs-title">🔄 Dự bị:</div>';
|
| 166 |
+
(lineups.home_subs || []).forEach(p=>{
|
| 167 |
+
h += '<div style="font-size:10px;color:#888;padding:2px 0">' + esc(p) + '</div>';
|
| 168 |
+
});
|
| 169 |
+
}
|
| 170 |
+
h += '</div>';
|
| 171 |
+
// Away team
|
| 172 |
+
h += '<div class="md-team-box">';
|
| 173 |
+
h += '<div class="md-team-name">' + esc(lineups.away_team || 'Đội khách') + '</div>';
|
| 174 |
+
if(lineups.away_formation) h += '<div class="md-formation">Đội hình: ' + esc(lineups.away_formation) + '</div>';
|
| 175 |
+
h += '<ul class="md-player-list">';
|
| 176 |
+
(lineups.away_players || []).forEach((p,i)=>{
|
| 177 |
+
h += '<li class="md-player-item"><span class="md-player-no">' + (i+1) + '</span>' + esc(p) + '</li>';
|
| 178 |
+
});
|
| 179 |
+
h += '</ul>';
|
| 180 |
+
if(lineups.away_subs && lineups.away_subs.length > 0){
|
| 181 |
+
h += '<div class="md-subs-title">🔄 Dự bị:</div>';
|
| 182 |
+
(lineups.away_subs || []).forEach(p=>{
|
| 183 |
+
h += '<div style="font-size:10px;color:#888;padding:2px 0">' + esc(p) + '</div>';
|
| 184 |
+
});
|
| 185 |
+
}
|
| 186 |
+
h += '</div>';
|
| 187 |
+
h += '</div>';
|
| 188 |
+
return h;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
function renderH2H(matches){
|
| 192 |
+
let h = '';
|
| 193 |
+
matches.forEach(m=>{
|
| 194 |
+
const isLive = m.status === 'live';
|
| 195 |
+
h += '<div class="md-h2h-item">';
|
| 196 |
+
h += '<span class="md-h2h-date">' + esc(m.date || '') + '</span>';
|
| 197 |
+
h += '<span class="md-h2h-teams">';
|
| 198 |
+
h += '<span class="md-h2h-home">' + esc(m.home || '') + '</span>';
|
| 199 |
+
h += '<span class="md-h2h-score">' + esc(m.score || 'vs') + '</span>';
|
| 200 |
+
h += '<span class="md-h2h-away">' + esc(m.away || '') + '</span>';
|
| 201 |
+
h += '</span>';
|
| 202 |
+
if(isLive) h += '<span class="md-h2h-live">LIVE</span>';
|
| 203 |
+
h += '</div>';
|
| 204 |
+
});
|
| 205 |
+
return h;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Add the "Chi tiết" tab to the match overlay
|
| 209 |
+
function injectDetailTab(){
|
| 210 |
+
// Wait for overlay to exist
|
| 211 |
+
const check = setInterval(()=>{
|
| 212 |
+
const tabsContainer = document.querySelector('.mo-tabs');
|
| 213 |
+
if(tabsContainer && !document.querySelector('.mo-tab-detail')){
|
| 214 |
+
// Remove existing detail tab if any (old)
|
| 215 |
+
const existing = document.querySelector('.mo-tab-detail');
|
| 216 |
+
if(existing) existing.remove();
|
| 217 |
+
// Add new tab
|
| 218 |
+
const detailTab = document.createElement('span');
|
| 219 |
+
detailTab.className = 'mo-tab mo-tab-detail';
|
| 220 |
+
detailTab.textContent = '📋 Chi tiết';
|
| 221 |
+
detailTab.onclick = ()=>window.loadMatchTab('detail');
|
| 222 |
+
tabsContainer.appendChild(detailTab);
|
| 223 |
+
clearInterval(check);
|
| 224 |
+
}
|
| 225 |
+
}, 500);
|
| 226 |
+
// Stop checking after 30s
|
| 227 |
+
setTimeout(()=>clearInterval(check), 30000);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// Override openMatch to inject detail tab
|
| 231 |
+
const _origOpenMatch = window.openMatch;
|
| 232 |
+
if(_origOpenMatch){
|
| 233 |
+
window.openMatch = function(id){
|
| 234 |
+
_origOpenMatch(id);
|
| 235 |
+
setTimeout(injectDetailTab, 300);
|
| 236 |
+
};
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// Also inject on DOM ready
|
| 240 |
+
if(document.readyState === 'loading'){
|
| 241 |
+
document.addEventListener('DOMContentLoaded', ()=>setTimeout(injectDetailTab, 1000));
|
| 242 |
+
} else {
|
| 243 |
+
setTimeout(injectDetailTab, 1000);
|
| 244 |
+
}
|
| 245 |
+
})();
|