Skip to content

Commit d214f8d

Browse files
committed
weather
1 parent fbc2eea commit d214f8d

3 files changed

Lines changed: 69 additions & 9 deletions

File tree

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@
942942
</script>
943943
</header>
944944
<main>
945+
<div id="rain-banner">
946+
<div id="rain-banner-text"></div>
947+
</div>
945948
<section style="display: flex; align-items: center; gap: 0.5ch; margin-left: 4px;" class="only-show-on-mobile">
946949
<a href="atom.xml">⚛&nbsp;&nbsp;atom.xml</a>
947950
󱠡

js/weather.js

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const conditionsEmoji = document.getElementById('conditionsEmoji');
99
const currentTemp = document.getElementById('currentTemp');
1010
const low = document.getElementById('low');
1111
const high = document.getElementById('high');
12+
const rainDiv = document.getElementById('rain');
13+
const rainBanner = document.getElementById('rain-banner');
14+
const rainBannerText = document.getElementById('rain-banner-text');
1215

1316

1417
const setTime = () => {
@@ -68,9 +71,43 @@ const url = 'https://api.open-meteo.com/v1/forecast?'
6871
+ '&current=temperature_2m,is_day,weather_code'
6972
+ '&timezone=America%2FNew_York';
7073

74+
const simulateRain = false;
75+
76+
function updateRainBannerText() {
77+
if (!rainBannerText) return;
78+
const chunk = 'IT IS CURRENTLY RAINING IN NEW YORK ⋅ ';
79+
const repeatCount = Math.max(3, Math.ceil(window.innerWidth / 325) + 2);
80+
rainBannerText.textContent = chunk.repeat(repeatCount);
81+
}
82+
83+
function setRainState(isRaining) {
84+
if (rainDiv) {
85+
rainDiv.style.display = isRaining ? 'block' : 'none';
86+
}
87+
88+
if (rainBanner) {
89+
rainBanner.style.display = isRaining ? 'block' : 'none';
90+
if (isRaining) {
91+
updateRainBannerText();
92+
} else if (rainBannerText) {
93+
rainBannerText.textContent = '';
94+
}
95+
}
96+
}
97+
98+
setRainState(false);
99+
100+
window.addEventListener('resize', () => {
101+
if (rainBanner && rainBanner.style.display === 'block') {
102+
updateRainBannerText();
103+
}
104+
});
105+
71106
fetch(url)
72107
.then(response => response.json())
73108
.then(data => {
109+
const weatherCode = simulateRain ? 63 : data.current.weather_code;
110+
74111
currentTemp.textContent = data.current.temperature_2m.toFixed(1) + '°C';
75112
high.textContent = "H: " + data.daily.temperature_2m_max[0].toFixed(1) + '°C';
76113
low.textContent = "L: " + data.daily.temperature_2m_min[0].toFixed(1) + '°C';
@@ -89,7 +126,7 @@ fetch(url)
89126
// 85, 86 Snow showers slight and heavy
90127
// 95 * Thunderstorm: Slight or moderate
91128
// 96, 99 * Thunderstorm with slight and heavy hail
92-
switch (data.current.weather_code) {
129+
switch (weatherCode) {
93130
case 0: // Clear sky
94131
conditions.textContent = 'Clear sky';
95132
element.style.background = 'linear-gradient(0deg, #87CEEB, #FFD700)';
@@ -244,14 +281,8 @@ fetch(url)
244281
useSkyGradient();
245282
}
246283

247-
if (
248-
[51, 53, 55, 61, 63, 65, 80, 81, 82].includes(data.current.weather_code)
249-
) {
250-
const rainDiv = document.getElementById('rain');
251-
if (rainDiv) {
252-
rainDiv.style.display = 'block';
253-
}
254-
}
284+
const isRaining = [51, 53, 55, 61, 63, 65, 80, 81, 82].includes(weatherCode);
285+
setRainState(isRaining);
255286

256287

257288
const daily = data.daily.time.map((time, i) => ({
@@ -315,4 +346,7 @@ fetch(url)
315346
if (usedGradient) {
316347
document.getElementById('attribution').style.display = 'block';
317348
}
349+
})
350+
.catch(() => {
351+
setRainState(false);
318352
});

stylesheets/weather.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88
opacity: 0.7;
99
}
1010

11+
#rain-banner {
12+
display: none;
13+
width: 100%;
14+
background: rgb(92, 96, 98);
15+
}
16+
17+
#rain-banner-text {
18+
color: #ffffff;
19+
padding: 0.5ch;
20+
white-space: nowrap;
21+
text-transform: uppercase;
22+
animation: rain-banner-text-blink 3s step-end infinite;
23+
}
24+
25+
@keyframes rain-banner-text-blink {
26+
0%, 66% {
27+
opacity: 1;
28+
}
29+
66%, 100% {
30+
opacity: 0;
31+
}
32+
}
33+
1134
#rain {
1235
display: none;
1336
position: fixed;

0 commit comments

Comments
 (0)