diff --git a/metar.html b/metar.html index 990df91..437e573 100644 --- a/metar.html +++ b/metar.html @@ -806,15 +806,23 @@ return sections; } - function displayNewMetar() { + function displayMetar(index) { if (metars.length === 0) { metarDisplay.textContent = 'No METARs loaded.'; return; } - // Bias random selection towards the more interesting (higher-scored) METARs at the start of the array. - // Math.random() * Math.random() skews distribution towards 0. - const randomIndex = Math.floor(Math.random() * Math.random() * metars.length); - const metarString = metars[randomIndex].metar; + + let metarIndex; + if (index !== undefined && index >= 0 && index < metars.length) { + metarIndex = index; + } else { + // Bias random selection towards the more interesting (higher-scored) METARs at the start of the array. + // Math.random() * Math.random() skews distribution towards 0. + metarIndex = Math.floor(Math.random() * Math.random() * metars.length); + } + + const metarString = metars[metarIndex].metar; + window.location.hash = metarIndex; currentMetarSections = generateMetarSections(metarString); currentSectionIndex = 0; @@ -861,14 +869,21 @@ console.log(` - Score: ${metars[i].score.toFixed(2)}, METAR: ${metars[i].metar}`); } - displayNewMetar(); // Display initial METAR + const hash = window.location.hash.substring(1); + const initialIndex = parseInt(hash, 10); + + if (!isNaN(initialIndex) && initialIndex >= 0 && initialIndex < metars.length) { + displayMetar(initialIndex); + } else { + displayMetar(); // Display initial random METAR + } }) .catch(error => { console.error('Error fetching or parsing metars.txt:', error) metarDisplay.textContent = 'Could not load METARs.'; }); - newMetarBtn.addEventListener('click', displayNewMetar); + newMetarBtn.addEventListener('click', () => displayMetar()); decodeAllCheckbox.addEventListener('change', updateDisplay); function updateDisplay() {