diff --git a/src/main/java/cz/kamma/czb/BasketballServer.java b/src/main/java/cz/kamma/czb/BasketballServer.java index f16be56..9f2e55e 100644 --- a/src/main/java/cz/kamma/czb/BasketballServer.java +++ b/src/main/java/cz/kamma/czb/BasketballServer.java @@ -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; diff --git a/src/main/resources/index.html b/src/main/resources/index.html index 6913581..946c006 100644 --- a/src/main/resources/index.html +++ b/src/main/resources/index.html @@ -65,7 +65,6 @@ Vyber datum: -Načíst zápasy Vyber ligu: @@ -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 = ` - ${match.status} - ${league.name} - ${match.home.name} - ${match.away.name} - ${previewUrl ? 'Preview' : ''} - ${match.links.live && match.links.live.url ? 'Live' : ''} - ${match.links.tvcom && match.links.tvcom.url ? 'TV' : ''} - `; - - // 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 = ` + ${match.status} + ${league} + ${match.home.name} + ${match.away.name} + ${previewUrl ? 'Preview' : ''} + ${match.links.live && match.links.live.url ? 'Live' : ''} + ${match.links.tvcom && match.links.tvcom.url ? 'TV' : ''} + `; + + 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'); }