Spaces:
Running
Running
Fix match detail: pass full URL with slug to backend for HTML scraping
Browse files- static/match_detail.js +14 -3
static/match_detail.js
CHANGED
|
@@ -53,8 +53,9 @@
|
|
| 53 |
function esc(s){return String(s||'').replace(/[&<>"']/g,function(m){return{'&':'&','<':'<','>':'>','"':'"',"'":'''}[m]})}
|
| 54 |
|
| 55 |
const _origOpenMatch = window.openMatch;
|
| 56 |
-
window.openMatch = function(id){
|
| 57 |
if(id) window._currentEventId = String(id);
|
|
|
|
| 58 |
if(_origOpenMatch) _origOpenMatch.call(this, id);
|
| 59 |
setTimeout(function(){
|
| 60 |
injectDetailTab();
|
|
@@ -77,12 +78,17 @@
|
|
| 77 |
if(!el) return;
|
| 78 |
el.innerHTML = '<div class="md-no-data"><div style="display:inline-block;width:20px;height:20px;border:2px solid #333;border-top-color:#5cb87a;border-radius:50%;animation:mdspin .8s linear infinite;vertical-align:middle;margin-right:8px"></div>Đang tải chi tiết trận đấu...</div>';
|
| 79 |
const eventId = window._currentEventId;
|
|
|
|
| 80 |
if(!eventId){
|
| 81 |
el.innerHTML = '<div class="md-err">⚠️ Không tìm thấy mã trận đấu.<br><small>Hãy click vào một trận đấu cụ thể từ danh sách livescore.</small></div>';
|
| 82 |
return;
|
| 83 |
}
|
| 84 |
try{
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
if(!r.ok){
|
| 87 |
el.innerHTML = '<div class="md-err">⚠️ Lỗi máy chủ (' + r.status + ').<br><small>Event ID: ' + esc(String(eventId)) + '</small><br><button onclick="window.loadMatchTab(\'detail\')" style="margin-top:8px;background:#0066cc;border:none;color:#fff;padding:6px 14px;border-radius:8px;font-size:11px;cursor:pointer">Thử lại</button></div>';
|
| 88 |
return;
|
|
@@ -239,6 +245,7 @@
|
|
| 239 |
tabs.insertBefore(d, tabs.firstChild);
|
| 240 |
}
|
| 241 |
|
|
|
|
| 242 |
document.addEventListener('click', function(e){
|
| 243 |
const md = e.target.closest('.match-detail');
|
| 244 |
if(!md) return;
|
|
@@ -246,7 +253,11 @@
|
|
| 246 |
if(link){
|
| 247 |
const href = link.getAttribute('href') || '';
|
| 248 |
const m = href.match(/\/tran-dau\/(\d+)\//);
|
| 249 |
-
if(m){
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
}
|
| 251 |
}, true);
|
| 252 |
|
|
|
|
| 53 |
function esc(s){return String(s||'').replace(/[&<>"']/g,function(m){return{'&':'&','<':'<','>':'>','"':'"',"'":'''}[m]})}
|
| 54 |
|
| 55 |
const _origOpenMatch = window.openMatch;
|
| 56 |
+
window.openMatch = function(id, url){
|
| 57 |
if(id) window._currentEventId = String(id);
|
| 58 |
+
if(url) window._currentMatchUrl = String(url);
|
| 59 |
if(_origOpenMatch) _origOpenMatch.call(this, id);
|
| 60 |
setTimeout(function(){
|
| 61 |
injectDetailTab();
|
|
|
|
| 78 |
if(!el) return;
|
| 79 |
el.innerHTML = '<div class="md-no-data"><div style="display:inline-block;width:20px;height:20px;border:2px solid #333;border-top-color:#5cb87a;border-radius:50%;animation:mdspin .8s linear infinite;vertical-align:middle;margin-right:8px"></div>Đang tải chi tiết trận đấu...</div>';
|
| 80 |
const eventId = window._currentEventId;
|
| 81 |
+
const matchUrl = window._currentMatchUrl;
|
| 82 |
if(!eventId){
|
| 83 |
el.innerHTML = '<div class="md-err">⚠️ Không tìm thấy mã trận đấu.<br><small>Hãy click vào một trận đấu cụ thể từ danh sách livescore.</small></div>';
|
| 84 |
return;
|
| 85 |
}
|
| 86 |
try{
|
| 87 |
+
let apiUrl = '/api/match/' + eventId + '/detail';
|
| 88 |
+
if(matchUrl){
|
| 89 |
+
apiUrl += '?url=' + encodeURIComponent(matchUrl);
|
| 90 |
+
}
|
| 91 |
+
const r = await fetch(apiUrl);
|
| 92 |
if(!r.ok){
|
| 93 |
el.innerHTML = '<div class="md-err">⚠️ Lỗi máy chủ (' + r.status + ').<br><small>Event ID: ' + esc(String(eventId)) + '</small><br><button onclick="window.loadMatchTab(\'detail\')" style="margin-top:8px;background:#0066cc;border:none;color:#fff;padding:6px 14px;border-radius:8px;font-size:11px;cursor:pointer">Thử lại</button></div>';
|
| 94 |
return;
|
|
|
|
| 245 |
tabs.insertBefore(d, tabs.firstChild);
|
| 246 |
}
|
| 247 |
|
| 248 |
+
// Capture both event_id and full URL from match links
|
| 249 |
document.addEventListener('click', function(e){
|
| 250 |
const md = e.target.closest('.match-detail');
|
| 251 |
if(!md) return;
|
|
|
|
| 253 |
if(link){
|
| 254 |
const href = link.getAttribute('href') || '';
|
| 255 |
const m = href.match(/\/tran-dau\/(\d+)\//);
|
| 256 |
+
if(m){
|
| 257 |
+
window._currentEventId = m[1];
|
| 258 |
+
// Store the full URL (with slug) for HTML scraping
|
| 259 |
+
window._currentMatchUrl = href.startsWith('http') ? href : 'https://bongda.com.vn' + href;
|
| 260 |
+
}
|
| 261 |
}
|
| 262 |
}, true);
|
| 263 |
|