feat: Make METARs sharable via URL hash
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
+22
-7
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user