@@ -9,6 +9,9 @@ const conditionsEmoji = document.getElementById('conditionsEmoji');
99const currentTemp = document . getElementById ( 'currentTemp' ) ;
1010const low = document . getElementById ( 'low' ) ;
1111const 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
1417const setTime = ( ) => {
@@ -68,9 +71,43 @@ const url = 'https://api.open-meteo.com/v1/forecast?'
6871 + '¤t=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+
71106fetch ( 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 } ) ;
0 commit comments