fix: Update METAR on hash change and prevent re-display of current METAR

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-14 18:03:58 -07:00
parent ff9f9de982
commit 467cb9defc
+13
View File
@@ -76,6 +76,7 @@
let currentMetarSections = []; let currentMetarSections = [];
let currentSectionIndex = 0; let currentSectionIndex = 0;
let currentMetarIndex = -1;
// --- METAR Ranking --- // --- METAR Ranking ---
@@ -832,6 +833,11 @@
metarIndex = Math.floor(Math.random() * Math.random() * metars.length); metarIndex = Math.floor(Math.random() * Math.random() * metars.length);
} }
if (metarIndex === currentMetarIndex) {
return; // Already displaying this METAR
}
currentMetarIndex = metarIndex;
const metarString = metars[metarIndex].metar; const metarString = metars[metarIndex].metar;
history.replaceState(null, '', '#' + metarIndex); history.replaceState(null, '', '#' + metarIndex);
@@ -896,6 +902,13 @@
newMetarBtn.addEventListener('click', () => displayMetar()); newMetarBtn.addEventListener('click', () => displayMetar());
decodeAllCheckbox.addEventListener('change', updateDisplay); decodeAllCheckbox.addEventListener('change', updateDisplay);
window.addEventListener('hashchange', () => {
const hash = window.location.hash.substring(1);
const index = parseInt(hash, 10);
if (!isNaN(index) && index >= 0 && index < metars.length) {
displayMetar(index);
}
});
function updateDisplay() { function updateDisplay() {
if (currentMetarSections.length === 0) return; if (currentMetarSections.length === 0) return;