feat: Make METARs sharable via URL hash

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-14 17:54:27 -07:00
parent b8b9cf2604
commit 1b4abda7e4
+22 -7
View File
@@ -806,15 +806,23 @@
return sections; return sections;
} }
function displayNewMetar() { function displayMetar(index) {
if (metars.length === 0) { if (metars.length === 0) {
metarDisplay.textContent = 'No METARs loaded.'; metarDisplay.textContent = 'No METARs loaded.';
return; 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. let metarIndex;
const randomIndex = Math.floor(Math.random() * Math.random() * metars.length); if (index !== undefined && index >= 0 && index < metars.length) {
const metarString = metars[randomIndex].metar; 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); currentMetarSections = generateMetarSections(metarString);
currentSectionIndex = 0; currentSectionIndex = 0;
@@ -861,14 +869,21 @@
console.log(` - Score: ${metars[i].score.toFixed(2)}, METAR: ${metars[i].metar}`); 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 => { .catch(error => {
console.error('Error fetching or parsing metars.txt:', error) console.error('Error fetching or parsing metars.txt:', error)
metarDisplay.textContent = 'Could not load METARs.'; metarDisplay.textContent = 'Could not load METARs.';
}); });
newMetarBtn.addEventListener('click', displayNewMetar); newMetarBtn.addEventListener('click', () => displayMetar());
decodeAllCheckbox.addEventListener('change', updateDisplay); decodeAllCheckbox.addEventListener('change', updateDisplay);
function updateDisplay() { function updateDisplay() {