sort by time
This commit is contained in:
parent
63a4549a8d
commit
843e2bf749
@ -22,9 +22,6 @@ import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
public class BasketballServer {
|
||||
|
||||
private static JsonNode cachedData;
|
||||
private static final Object lock = new Object();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
fetchDataForDate("Sat Nov 01 2025 01:00:00 GMT+0100 (Central European Standard Time)"); // inicialní fetch
|
||||
|
||||
@ -60,7 +57,6 @@ public class BasketballServer {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode data = mapper.readTree(content.toString());
|
||||
synchronized (lock) { cachedData = data; }
|
||||
System.out.println("Data fetched successfully for date: " + dateParam);
|
||||
return data;
|
||||
|
||||
|
||||
@ -65,7 +65,6 @@
|
||||
|
||||
<label for="date">Vyber datum:</label>
|
||||
<input type="date" id="date" onchange="loadMatches()"/>
|
||||
<button onclick="loadMatches()">Načíst zápasy</button>
|
||||
|
||||
<label for="league">Vyber ligu:</label>
|
||||
<select id="league" onchange="filterMatches()">
|
||||
@ -120,10 +119,11 @@ async function loadMatches() {
|
||||
let closestRow = null;
|
||||
const now = new Date();
|
||||
|
||||
const allMatches = [];
|
||||
|
||||
data.leagues.forEach(league => {
|
||||
// --- kontrola, zda liga má alespoň jeden zápas s TV odkazem ---
|
||||
const hasTV = league.matches.some(m => m.links.tvcom && m.links.tvcom.url);
|
||||
if (!hasTV) return; // přeskočit ligu bez TV zápasů
|
||||
if (!hasTV) return;
|
||||
|
||||
// přidat do select boxu
|
||||
const option = document.createElement('option');
|
||||
@ -132,53 +132,64 @@ async function loadMatches() {
|
||||
select.appendChild(option);
|
||||
|
||||
league.matches.forEach(match => {
|
||||
if (!match.links.live && !match.links.tvcom) return; // přeskočit zápasy bez Live a TV
|
||||
if (!match.links.live && !match.links.tvcom) return;
|
||||
|
||||
const tr = document.createElement('tr');
|
||||
tr.dataset.league = league.name;
|
||||
|
||||
// doplnit https://cz.basketball pokud preview.url nezačíná http/https
|
||||
let previewUrl = '';
|
||||
if (match.links.preview && match.links.preview.url) {
|
||||
previewUrl = match.links.preview.url;
|
||||
if (!previewUrl.startsWith('http://') && !previewUrl.startsWith('https://')) {
|
||||
previewUrl = 'https://cz.basketball' + previewUrl;
|
||||
}
|
||||
}
|
||||
|
||||
tr.innerHTML = `
|
||||
<td>${match.status}</td>
|
||||
<td>${league.name}</td>
|
||||
<td>${match.home.name}</td>
|
||||
<td>${match.away.name}</td>
|
||||
<td>${previewUrl ? '<a href="'+previewUrl+'">Preview</a>' : ''}</td>
|
||||
<td>${match.links.live && match.links.live.url ? '<a href="'+match.links.live.url+'" target="_blank">Live</a>' : ''}</td>
|
||||
<td>${match.links.tvcom && match.links.tvcom.url ? '<a href="'+match.links.tvcom.url+'" target="_blank">TV</a>' : ''}</td>
|
||||
`;
|
||||
|
||||
// zvýraznit zápasy s Nymburkem
|
||||
if ((match.home.name && match.home.name.includes('Nymburk')) ||
|
||||
(match.away.name && match.away.name.includes('Nymburk'))) {
|
||||
tr.classList.add('nymburk');
|
||||
}
|
||||
|
||||
// zvýraznit nejbližší zápas (Live zápasy)
|
||||
if (match.links.live && match.links.live.url) {
|
||||
const [hours, minutes] = match.status.split(':').map(Number);
|
||||
if (!isNaN(hours) && !isNaN(minutes)) {
|
||||
const matchDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
|
||||
const diff = matchDate - now;
|
||||
if (diff >= 0 && diff < closestTimeDiff) {
|
||||
closestTimeDiff = diff;
|
||||
closestRow = tr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tbody.appendChild(tr);
|
||||
allMatches.push({ league: league.name, match });
|
||||
});
|
||||
});
|
||||
|
||||
// --- Seřadit podle času ---
|
||||
allMatches.sort((a, b) => {
|
||||
const parseTime = s => {
|
||||
if (!s || !s.match(/^\d{1,2}:\d{2}$/)) return Infinity;
|
||||
const [h, m] = s.split(':').map(Number);
|
||||
return h * 60 + m;
|
||||
};
|
||||
return parseTime(a.match.status) - parseTime(b.match.status);
|
||||
});
|
||||
|
||||
|
||||
// --- Vytvořit tabulku ---
|
||||
allMatches.forEach(({ league, match }) => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.dataset.league = league;
|
||||
|
||||
let previewUrl = '';
|
||||
if (match.links.preview && match.links.preview.url) {
|
||||
previewUrl = match.links.preview.url;
|
||||
if (!previewUrl.startsWith('http://') && !previewUrl.startsWith('https://')) {
|
||||
previewUrl = 'https://cz.basketball' + previewUrl;
|
||||
}
|
||||
}
|
||||
|
||||
tr.innerHTML = `
|
||||
<td>${match.status}</td>
|
||||
<td>${league}</td>
|
||||
<td>${match.home.name}</td>
|
||||
<td>${match.away.name}</td>
|
||||
<td>${previewUrl ? '<a href="'+previewUrl+'">Preview</a>' : ''}</td>
|
||||
<td>${match.links.live && match.links.live.url ? '<a href="'+match.links.live.url+'" target="_blank">Live</a>' : ''}</td>
|
||||
<td>${match.links.tvcom && match.links.tvcom.url ? '<a href="'+match.links.tvcom.url+'" target="_blank">TV</a>' : ''}</td>
|
||||
`;
|
||||
|
||||
if ((match.home.name && match.home.name.includes('Nymburk')) ||
|
||||
(match.away.name && match.away.name.includes('Nymburk'))) {
|
||||
tr.classList.add('nymburk');
|
||||
}
|
||||
|
||||
const [hours, minutes] = match.status.split(':').map(Number);
|
||||
if (!isNaN(hours) && !isNaN(minutes)) {
|
||||
const matchDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
|
||||
const diff = matchDate - now;
|
||||
if (diff >= 0 && diff < closestTimeDiff) {
|
||||
closestTimeDiff = diff;
|
||||
closestRow = tr;
|
||||
}
|
||||
}
|
||||
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
|
||||
if (closestRow) closestRow.classList.add('highlight');
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user