diff --git a/app.js b/app.js index e5ea2f0..d28c358 100644 --- a/app.js +++ b/app.js @@ -2030,3 +2030,36 @@ function showTimmySpeech(text) { timmySpeechSprite = sprite; timmySpeechState = { startTime: clock.getElapsedTime(), sprite }; } + +// === BITCOIN BLOCK HEIGHT === +// Polls blockstream.info every 60 s for the current tip block height. +// Shows a flash animation when the block number increments. + +const blockHeightDisplay = document.getElementById('block-height-display'); +const blockHeightValue = document.getElementById('block-height-value'); +let lastKnownBlockHeight = null; + +async function fetchBlockHeight() { + try { + const res = await fetch('https://blockstream.info/api/blocks/tip/height'); + if (!res.ok) return; + const height = parseInt(await res.text(), 10); + if (isNaN(height)) return; + + if (lastKnownBlockHeight !== null && height !== lastKnownBlockHeight) { + // New block — trigger flash + blockHeightDisplay.classList.remove('fresh'); + // Force reflow so animation restarts + void blockHeightDisplay.offsetWidth; + blockHeightDisplay.classList.add('fresh'); + } + + lastKnownBlockHeight = height; + blockHeightValue.textContent = height.toLocaleString(); + } catch (_) { + // Network unavailable — keep last known value + } +} + +fetchBlockHeight(); +setInterval(fetchBlockHeight, 60000); diff --git a/index.html b/index.html index a5715f5..93e9dca 100644 --- a/index.html +++ b/index.html @@ -51,6 +51,11 @@