// VARIABILI DA MODIFICARE - VARIABLES TO MODIFY // const jsonUrl = 'https://api.vichingo455.freeddns.org/TabelloneTreni/stazioni.json'; //JSON statico - static JSON const ApiUri = 'PLACEHOLDER'; //JSON Dinamico - Dynamic JSON // IMPORTANTE!! NON MODIFICARE SOTTO!! - IMPORTANT!! DO NOT MODIFY THE CODE BELOW!! // let ultimaRichiesta = null; let intervalloAggiornamento = null; const delay = ms => new Promise(res => setTimeout(res, ms)); async function caricaStazioni() { try { const response = await fetch(jsonUrl); const stazioni = await response.json(); const select = document.getElementById('stazione'); select.innerHTML = ''; stazioni.forEach(stazione => { const option = document.createElement('option'); option.value = stazione.key; option.textContent = stazione.text; select.appendChild(option); }); } catch (error) { console.error('Errore nel caricamento delle stazioni:', error); document.getElementById('stazione').innerHTML = ''; } } async function caricaDati(event = null, richiestaManuale = false) { if (event) event.preventDefault(); const placeId = document.getElementById("stazione").value; const arrivals = document.getElementById("tipo").value; const corpo = document.getElementById("corpoTabella"); const tabella = document.getElementById("tabellaDati"); if (!placeId) { if (richiestaManuale) alert("Seleziona una stazione."); return; } // Salva la richiesta corrente per i refresh automatici ultimaRichiesta = { placeId, arrivals }; const url = `${ApiUri}/?Arrivals=${arrivals}&PlaceId=${placeId}&exclude=0,1,7,8`; try { if (richiestaManuale) { tabella.style.display = "table"; corpo.innerHTML = `