better UI

This commit is contained in:
Radek Davidek 2025-11-02 13:19:21 +01:00
parent 843e2bf749
commit 21cb991f9a

View File

@ -1,52 +1,89 @@
<!DOCTYPE html>
<html>
<html lang="cs">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CZ.Basketball - zápasy</title>
<link rel="icon" type="image/png" href="https://cz.basketball/img/logo-icon.png">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', Arial, sans-serif;
background: #f4f7f9;
color: #333;
margin: 20px;
margin: 10px 16px;
}
h1 { color: #2c3e50; }
label { margin-right: 8px; font-weight: 500; }
input, select, button {
padding: 6px 10px;
margin-right: 10px;
h1 {
color: #2c3e50;
font-size: 1.6rem;
text-align: center;
margin-bottom: 20px;
}
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-bottom: 10px;
justify-content: center;
}
label { font-weight: 500; }
input, select {
padding: 8px 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
border-radius: 6px;
font-size: 15px;
min-width: 140px;
}
button {
background-color: #3498db;
color: white;
border: none;
border-radius: 6px;
padding: 8px 12px;
font-size: 15px;
cursor: pointer;
transition: background 0.3s;
}
button:hover { background-color: #2980b9; }
.radio-group {
text-align: center;
margin: 8px 0 16px 0;
}
.radio-group label {
margin-right: 12px;
font-size: 15px;
}
#loading, #error {
text-align: center;
margin: 10px 0;
font-weight: 500;
}
#loading { color: #3498db; }
#error { color: red; }
.table-container {
overflow-x: auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
table {
border-collapse: collapse;
width: 100%;
background-color: white;
border-radius: 6px;
overflow: hidden;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
min-width: 700px;
}
th, td {
border-bottom: 1px solid #eee;
padding: 10px;
text-align: left;
font-size: 14px;
}
th {
background-color: #3498db;
color: white;
font-weight: 500;
position: sticky;
top: 0;
}
tr.highlight {
background-color: #ffeb3b !important;
@ -58,19 +95,37 @@
tr:nth-child(even) { background-color: #f9f9f9; }
a { color: #2980b9; text-decoration: none; }
a:hover { text-decoration: underline; }
@media (max-width: 600px) {
h1 { font-size: 1.3rem; margin-bottom: 12px; }
.controls { flex-direction: column; align-items: stretch; }
input, select { width: 100%; font-size: 16px; }
.radio-group label { display: block; margin: 4px 0; }
th, td { padding: 8px; font-size: 13px; }
}
</style>
</head>
<body>
<h1>CZ.Basketball - zápasy</h1>
<h1>CZ.Basketball zápasy</h1>
<label for="date">Vyber datum:</label>
<div class="controls">
<label for="date">Datum:</label>
<input type="date" id="date" onchange="loadMatches()"/>
<label for="league">Vyber ligu:</label>
<label for="league">Liga:</label>
<select id="league" onchange="filterMatches()">
<option value="">Všechny ligy</option>
</select>
</div>
<div class="radio-group">
<label><input type="radio" name="tvfilter" value="tv" checked>TV stream</label>
<label><input type="radio" name="tvfilter" value="live">Live Score</label>
<label><input type="radio" name="tvfilter" value="all">Všechny zápasy</label>
</div>
<div id="loading" style="display:none;">🔄 Načítám zápasy...</div>
<div id="error" style="display:none;">❌ Nepodařilo se načíst data.</div>
<div class="table-container">
<table id="matches">
<thead>
<tr>
@ -85,61 +140,81 @@
</thead>
<tbody></tbody>
</table>
</div>
<script>
// --- Nastavit kalendář na aktuální den při načtení stránky ---
let allMatchesGlobal = [];
window.addEventListener('DOMContentLoaded', () => {
const today = new Date();
const yyyy = today.getFullYear();
const mm = String(today.getMonth() + 1).padStart(2, '0');
const dd = String(today.getDate()).padStart(2, '0');
document.getElementById('date').value = `${yyyy}-${mm}-${dd}`;
loadMatches(); // načíst zápasy pro dnešní datum
loadMatches();
});
// --- Načíst zápasy z API ---
async function loadMatches() {
const loadingEl = document.getElementById('loading');
const errorEl = document.getElementById('error');
loadingEl.style.display = 'block';
errorEl.style.display = 'none';
const dateInput = document.getElementById('date').value;
let url = '/api/matches';
if (dateInput) url += '?date=' + encodeURIComponent(dateInput);
try {
const res = await fetch(url);
if (!res.ok) throw new Error('HTTP error');
const data = await res.json();
const select = document.getElementById('league');
allMatchesGlobal = [];
if (!data || !data.leagues) throw new Error('No data');
data.leagues.forEach(league => {
league.matches.forEach(match => {
allMatchesGlobal.push({ league: league.name, match });
});
});
renderMatches(allMatchesGlobal);
} catch (err) {
errorEl.style.display = 'block';
console.error(err);
} finally {
loadingEl.style.display = 'none';
}
}
function renderMatches(matches) {
const tbody = document.querySelector('#matches tbody');
const select = document.getElementById('league');
tbody.innerHTML = '';
select.innerHTML = '<option value="">Všechny ligy</option>';
if (!data || !data.leagues) return;
const tvFilter = document.querySelector('input[name="tvfilter"]:checked').value;
const filteredMatches = matches.filter(m => {
const hasTV = m.match.links.tvcom && m.match.links.tvcom.url;
const hasLive = m.match.links.live && m.match.links.live.url;
if(tvFilter === 'tv') return !!hasTV;
if(tvFilter === 'live') return !!hasLive;
return true;
});
const leagues = [...new Set(filteredMatches.map(m => m.league))];
leagues.forEach(name => {
const opt = document.createElement('option');
opt.value = name;
opt.textContent = name;
select.appendChild(opt);
});
const now = new Date();
let closestTimeDiff = Infinity;
let closestRow = null;
const now = new Date();
const allMatches = [];
data.leagues.forEach(league => {
const hasTV = league.matches.some(m => m.links.tvcom && m.links.tvcom.url);
if (!hasTV) return;
// přidat do select boxu
const option = document.createElement('option');
option.value = league.name;
option.textContent = league.name;
select.appendChild(option);
league.matches.forEach(match => {
if (!match.links.live && !match.links.tvcom) return;
allMatches.push({ league: league.name, match });
});
});
// --- Seřadit podle času ---
allMatches.sort((a, b) => {
filteredMatches.sort((a, b) => {
const parseTime = s => {
if(!s || !s.match(/^\d{1,2}:\d{2}$/)) return Infinity;
const [h,m] = s.split(':').map(Number);
@ -148,28 +223,29 @@ async function loadMatches() {
return parseTime(a.match.status) - parseTime(b.match.status);
});
// --- Vytvořit tabulku ---
allMatches.forEach(({ league, match }) => {
filteredMatches.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://')) {
if(!previewUrl.startsWith('http') && !previewUrl.startsWith('https')){
previewUrl = 'https://cz.basketball' + previewUrl;
}
}
const tvUrl = match.links.tvcom && match.links.tvcom.url;
const liveUrl = match.links.live && match.links.live.url;
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>
<td>${previewUrl ? '<a href="'+previewUrl+'" target="_blank">Preview</a>' : ''}</td>
<td>${liveUrl ? '<a href="'+liveUrl+'" target="_blank">Live</a>' : ''}</td>
<td>${tvUrl ? '<a href="'+tvUrl+'" target="_blank">TV</a>' : ''}</td>
`;
if((match.home.name && match.home.name.includes('Nymburk')) ||
@ -191,15 +267,21 @@ async function loadMatches() {
});
if(closestRow) closestRow.classList.add('highlight');
filterMatches();
}
// --- Filtrovat podle ligy ---
function filterMatches() {
const league = document.getElementById('league').value;
document.querySelectorAll('#matches tbody tr').forEach(row => {
row.style.display = (!league || row.dataset.league===league) ? '' : 'none';
});
}
document.querySelectorAll('input[name="tvfilter"]').forEach(radio => {
radio.addEventListener('change', () => {
renderMatches(allMatchesGlobal);
});
});
</script>
</body>
</html>