-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
614 lines (545 loc) · 28.6 KB
/
index.html
File metadata and controls
614 lines (545 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clock & Weather</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Fonts - Inter -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<!-- Favicon link - Add an ID to easily target it with JavaScript -->
<!-- The initial href is a tiny transparent SVG, which will be immediately overwritten by JS -->
<link rel="icon" id="favicon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3C/svg%3E">
<style>
body {
font-family: 'Inter', sans-serif;
background: #000000; /* Solid black background */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
color: #e2e8f0; /* Light text color */
user-select: none; /* Disable text selection */
-webkit-user-select: none; /* For Safari */
-moz-user-select: none; /* For Firefox */
-ms-user-select: none; /* For Internet Explorer/Edge */
}
.widget-container {
/* Light grey gradient for the main foreground tile */
background: linear-gradient(135deg, rgba(200, 200, 200, 0.1), rgba(240, 240, 240, 0.1));
backdrop-filter: blur(20px) saturate(180%); /* Frosted glass effect */
-webkit-backdrop-filter: blur(20px) saturate(180%); /* Safari support */
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 20px;
padding: 30px;
width: 100%; /* Takes full width up to max-width */
max-width: 900px; /* Fixed maximum width for desktop view */
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: row; /* Default: row for desktop */
flex-wrap: wrap; /* Allow tiles to wrap if screen is too small */
justify-content: center; /* Center items within the container */
align-items: stretch; /* IMPORTANT: Ensures flex items (tiles) stretch to the same height */
gap: 25px; /* Consistent gap between tiles */
position: relative;
overflow: hidden; /* Ensures blur doesn't bleed */
}
.widget-tile {
background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
gap: 10px;
flex: 1; /* Allow tiles to grow and shrink */
min-width: 280px; /* Minimum width for weather/forecast tiles before wrapping */
max-width: 100%; /* Ensures tiles don't overflow their container */
}
.widget-tile.clock-tile {
flex-basis: 100%; /* Clock tile always takes full width of the container */
max-width: 100%;
}
/* For weather and forecast tiles, make them roughly half width on desktop */
.widget-tile:not(.clock-tile) {
flex-basis: calc(50% - 12.5px); /* Approximately 50% minus half the gap (25px / 2 = 12.5px) */
max-width: calc(50% - 12.5px);
}
/* Mobile adjustments: stacking tiles for portrait */
@media (max-width: 767px) {
.widget-container {
flex-direction: column; /* Stack vertically on small screens */
padding: 20px;
gap: 20px;
max-width: 100%; /* Allow full width on mobile */
}
.widget-tile,
.widget-tile:not(.clock-tile),
.widget-tile.clock-tile { /* All tiles take full width on small screens */
min-width: 100%;
max-width: 100%;
flex-basis: auto; /* Allow flex to determine size based on content and available space */
padding: 15px;
}
.clock-time {
font-size: 2.8rem;
}
.clock-date {
font-size: 1rem;
}
.weather-current-temp {
font-size: 2rem;
}
/* Current Weather Details Grid - Now a flex column on mobile for consistent left alignment */
#current-weather-details-grid { /* Added ID to the parent div in HTML */
display: flex;
flex-direction: column;
gap: 10px; /* Space between each detail item (Wind, Humidity, etc.) */
}
.weather-detail-item {
display: flex;
align-items: center;
gap: 8px; /* Space between icon and text */
font-size: 1rem;
color: #cbd5e0;
/* No flex-basis or min-width needed here as they are stacked vertically */
}
.weather-detail-item > span:first-child { /* The emoji icon */
flex-shrink: 0; /* Prevent emoji from shrinking */
}
/* AQI Status fix for mobile - Now back on one line */
.aqi-container {
display: flex;
flex-direction: row; /* Back to row for one line display */
align-items: center; /* Vertically align items */
/* Removed gap: 5px; from here */
margin-left: 0; /* Reset any previous left margin */
}
.aqi-container #aqi-status {
margin-top: 0px; /* Reset margin */
font-size: 1rem; /* Back to normal font size */
margin-left: 10px; /* <--- INCREASED THIS VALUE for more spacing from '28' */
}
/* Ensure values like wind speed/direction/humidity stay on one line */
.weather-detail-item #wind-speed,
.weather-detail-item #wind-direction,
.weather-detail-item #humidity {
white-space: nowrap; /* Prevent these values from wrapping */
}
/* Forecast item alignment fix for mobile */
.weather-forecast-item {
display: grid; /* Use grid for better control */
grid-template-columns: auto 40px 1fr auto; /* Day, Emoji, Description (takes remaining space), Temp */
align-items: center; /* Vertically align items */
gap: 5px; /* Small gap between grid items */
}
.weather-forecast-item .weather-description-text {
white-space: normal; /* Allow text to wrap */
word-break: break-word; /* Break long words if necessary */
text-align: left;
}
}
/* Mobile Landscape adjustments: mimic desktop row layout */
@media (max-width: 767px) and (orientation: landscape) {
.widget-container {
flex-direction: row; /* Arrange in a row */
flex-wrap: wrap;
justify-content: center;
align-items: stretch;
gap: 20px; /* Slightly smaller gap for landscape mobile */
padding: 20px;
max-width: 700px; /* Constrain width for better readability on landscape phones */
}
.widget-tile.clock-tile {
flex-basis: 100%; /* Clock tile still takes full width */
max-width: 100%;
}
.widget-tile:not(.clock-tile) {
flex-basis: calc(50% - 10px); /* Roughly half width for weather/forecast tiles */
min-width: unset; /* Remove min-width to allow more flexibility */
max-width: calc(50% - 10px);
}
.clock-time {
font-size: 3rem; /* Slightly larger for landscape */
}
.clock-date {
font-size: 1.1rem;
}
.weather-current-temp {
font-size: 2.2rem;
}
/* Reset Current Weather Details Grid for landscape */
#current-weather-details-grid {
display: grid; /* Back to grid for landscape */
grid-template-columns: 1fr 1fr; /* Two columns */
gap-y: 2px; /* Restore original gap */
gap-x: 4px; /* Restore original gap */
}
/* Reset AQI and Forecast for landscape if needed, or let the default desktop styles apply */
.aqi-container {
flex-direction: row; /* Back to row for landscape */
align-items: center;
margin-left: 0; /* Reset margin */
}
.aqi-container #aqi-status {
margin-top: 0;
margin-left: 8px; /* Standard gap for landscape */
}
.weather-forecast-item {
display: flex; /* Back to flex for landscape */
justify-content: space-between;
align-items: center;
gap: 0; /* Remove gap set by grid */
}
.weather-forecast-item .weather-description-text {
white-space: nowrap; /* Prevent wrapping for landscape */
text-align: right; /* Default alignment */
}
}
.widget-tile.gradient-1 {
background: linear-gradient(135deg, rgba(66, 153, 225, 0.2), rgba(66, 153, 225, 0.05)); /* Blue-ish gradient */
}
.widget-tile.gradient-2 {
background: linear-gradient(135deg, rgba(49, 196, 141, 0.2), rgba(49, 196, 141, 0.05)); /* Green-ish gradient */
}
.widget-tile.gradient-3 {
background: linear-gradient(135deg, rgba(237, 137, 54, 0.2), rgba(237, 137, 54, 0.05)); /* Orange-ish gradient */
}
.clock-time {
font-size: 3.5rem;
font-weight: 700;
letter-spacing: -0.05em;
text-align: center;
color: #a7f3d0; /* Light green for time */
text-shadow: 0 0 15px rgba(167, 243, 208, 0.4);
}
.clock-date {
font-size: 1.2rem;
font-weight: 500;
text-align: center;
color: #cbd5e0;
}
.special-day {
font-size: 1rem;
font-weight: 400;
text-align: center;
color: #fcba03; /* Amber for special day */
margin-top: 5px;
}
.weather-current-temp {
font-size: 2.5rem;
font-weight: 600;
color: #90cdf4; /* Light blue for temperature */
display: flex;
align-items: center;
gap: 10px;
}
.weather-detail-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 1rem;
color: #cbd5e0;
}
.weather-forecast-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0;
border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.weather-forecast-item:first-child {
border-top: none;
}
.footer {
text-align: center;
margin-top: 30px;
font-size: 0.9rem;
color: #a0aec0;
width: 100%; /* Ensure footer spans full width */
}
</style>
</head>
<body oncontextmenu="return false;">
<div class="widget-container">
<!-- Clock and Date -->
<div class="widget-tile gradient-1 clock-tile">
<div id="clock-time" class="clock-time">--:--:-- --</div>
<div id="clock-date" class="clock-date">Loading Date...</div>
<div id="special-day" class="special-day hidden"></div>
</div>
<!-- Current Weather -->
<div class="widget-tile gradient-2">
<div class="flex items-center justify-between mb-3">
<h3 class="text-xl font-semibold text-white">Current Weather</h3>
<span id="weather-location" class="text-sm text-gray-400">Thiruvananthapuram, Kerala</span>
</div>
<div id="current-weather-display" class="flex flex-col gap-2">
<div class="weather-current-temp">
<span id="current-temp">--°C</span>
<span id="weather-emoji" class="text-4xl"></span>
<span id="weather-description" class="text-xl font-medium text-gray-300"></span>
</div>
<!-- Added ID for easier targeting in CSS -->
<div id="current-weather-details-grid" class="grid grid-cols-2 gap-y-2 gap-x-4 text-sm">
<div class="weather-detail-item"><span class="text-lg">💨</span> Wind: <span id="wind-speed">-- km/h</span> <span id="wind-direction"></span></div>
<div class="weather-detail-item"><span class="text-lg">💧</span> Humidity: <span id="humidity">--%</span></div>
<div class="weather-detail-item"><span class="text-lg">🌧️</span> Rainfall: <span id="rainfall">-- mm</span></div>
<!-- Modified AQI display for better mobile alignment -->
<div class="weather-detail-item">
<span class="text-lg">☁️</span> AQI:
<div class="aqi-container">
<span id="aqi">--</span>
<span id="aqi-status"></span>
</div>
</div>
</div>
</div>
<div id="current-weather-loading" class="text-center text-gray-400">Loading current weather...</div>
<div id="current-weather-error" class="text-center text-red-400 hidden">Error loading weather.</div>
</div>
<!-- 3-Day Forecast -->
<div class="widget-tile gradient-3">
<h3 class="text-xl font-semibold text-white mb-2">Next 3 Days Forecast</h3>
<div id="forecast-display" class="flex flex-col">
<!-- Forecast items will be injected here by JS -->
</div>
<div id="forecast-loading" class="text-center text-gray-400">Loading forecast...</div>
<div id="forecast-error" class="text-center text-red-400 hidden">Error loading forecast.</div>
</div>
<!-- Footer -->
<div class="footer">
Made with ❤️ by Naveen.
</div>
</div>
<script>
// --- Wake Lock API ---
let wakeLock = null;
const requestWakeLock = async () => {
try {
wakeLock = await navigator.wakeLock.request('screen');
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
};
// Request wake lock when the tab becomes active
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
requestWakeLock();
} else if (wakeLock !== null) {
wakeLock.release();
wakeLock = null;
}
});
// Request wake lock on load
window.onload = () => {
if ('wakeLock' in navigator) {
requestWakeLock();
} else {
console.warn('Wake Lock API not supported in this browser.');
}
updateClock();
fetchWeather();
};
// --- Clock and Date ---
function updateClock() {
const now = new Date();
// Digital Clock (12-hour format with seconds and AM/PM)
let hours = now.getHours();
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
const ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // The hour '0' should be '12'
const timeString = `${hours.toString().padStart(2, '0')}:${minutes}:${seconds} ${ampm}`;
document.getElementById('clock-time').textContent = timeString;
// Date (Indian Calendar)
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const dateString = now.toLocaleDateString('en-IN', options); // 'en-IN' for Indian locale
document.getElementById('clock-date').textContent = dateString;
// Special Day Check (Hardcoded for demonstration)
checkSpecialDay(now);
}
const specialDays = {
// Example special days (Month is 0-indexed: Jan=0, Feb=1, etc.)
"1-26": "Republic Day 🇮🇳",
"8-15": "Independence Day 🇮🇳",
"9-2": "Onam 🌾", // Example for 2025, adjust as needed
"9-23": "Dussehra / Vijayadashami ✨", // Example for 2025
"10-2": "Gandhi Jayanti 🕊️",
"10-21": "Diwali 🪔", // Example for 2025
"11-1": "Kerala Piravi 🌴",
"11-15": "Children's Day 👶",
"12-25": "Christmas 🎄"
};
function checkSpecialDay(date) {
const monthDay = `${date.getMonth()}-${date.getDate()}`;
const specialDayElement = document.getElementById('special-day');
if (specialDays[monthDay]) {
specialDayElement.textContent = `🎉 ${specialDays[monthDay]}`;
specialDayElement.classList.remove('hidden');
} else {
specialDayElement.classList.add('hidden');
}
}
// Update clock every second
setInterval(updateClock, 1000);
// --- Weather and AQI ---
const WEATHER_API_URL = 'https://api.open-meteo.com/v1/forecast';
const AQI_API_URL = 'https://air-quality-api.open-meteo.com/v1/air-quality';
const LATITUDE = 8.4869; // Thiruvananthapuram
const LONGITUDE = 76.9366; // Thiruvananthapuram
const TIMEZONE = 'Asia%2FKolkata';
// Map Open-Meteo weather codes to emojis, descriptions, and FAVICON NAMES
const weatherCodeMap = {
0: { emoji: '☀️', description: 'Clear sky', favicon: 'clear_day' },
1: { emoji: '🌤️', description: 'Mainly clear', favicon: 'clear_day' },
2: { emoji: '⛅', description: 'Partly cloudy', favicon: 'partly_cloudy_day' },
3: { emoji: '☁️', description: 'Overcast', favicon: 'cloud' },
45: { emoji: '🌫️', description: 'Fog', favicon: 'foggy' },
48: { emoji: '🌫️', description: 'Depositing rime fog', favicon: 'foggy' },
51: { emoji: '🌧️', description: 'Light drizzle', favicon: 'rainy_light' },
53: { emoji: '🌧️', description: 'Moderate drizzle', favicon: 'rainy_light' },
55: { emoji: '🌧️', description: 'Dense drizzle', favicon: 'rainy_light' },
56: { emoji: '🌧️❄️', description: 'Light freezing drizzle', favicon: 'rainy_light' },
57: { emoji: '🌧️❄️', description: 'Dense freezing drizzle', favicon: 'rainy_light' },
61: { emoji: '☔', description: 'Slight rain', favicon: 'rainy_light' },
63: { emoji: '🌧️', description: 'Moderate rain', favicon: 'rainy' },
65: { emoji: '⛈️', description: 'Heavy rain', favicon: 'rainy_heavy' },
66: { emoji: '🌧️❄️', description: 'Light freezing rain', favicon: 'rainy_light' },
67: { emoji: '🌧️❄️', description: 'Heavy freezing rain', favicon: 'rainy_heavy' },
71: { emoji: '🌨️', description: 'Slight snow fall', favicon: 'snowing' },
73: { emoji: '🌨️', description: 'Moderate snow fall', favicon: 'rainy_snow' },
75: { emoji: '❄️', description: 'Heavy snow fall', favicon: 'snowing_heavy' },
77: { emoji: '❄️', description: 'Snow grains', favicon: 'weather_snowy' },
80: { emoji: '⛈️', description: 'Slight rain showers', favicon: 'rainy_light' },
81: { emoji: '⛈️', description: 'Moderate rain showers', favicon: 'rainy' },
82: { emoji: '⛈️', description: 'Violent rain showers', favicon: 'rainy_heavy' },
85: { emoji: '🌨️', description: 'Slight snow showers', favicon: 'sunny_snowing' },
86: { emoji: '🌨️', description: 'Heavy snow showers', favicon: 'snowing_heavy' },
95: { emoji: '⚡⛈️', description: 'Thunderstorm', favicon: 'thunderstorm' },
96: { emoji: '⚡⛈️', description: 'Thunderstorm with slight hail', favicon: 'thunderstorm' },
99: { emoji: '⚡⛈️', description: 'Thunderstorm with heavy hail', favicon: 'weather_hail' },
};
function getWeatherEmoji(code) {
return weatherCodeMap[code] ? weatherCodeMap[code].emoji : '❓';
}
function getWeatherDescription(code) {
return weatherCodeMap[code] ? weatherCodeMap[code].description : 'Unknown';
}
// Function to update the favicon using local files
function updateFavicon(weatherCode) {
const faviconLink = document.getElementById('favicon');
// Get the specific icon file name from your updated map
const iconFileName = weatherCodeMap[weatherCode] ? weatherCodeMap[weatherCode].favicon : 'question_mark';
// Set the favicon href to the local file path.
faviconLink.href = `favicons/${iconFileName}.svg`;
faviconLink.type = 'image/svg+xml';
}
// Function to convert wind degrees to cardinal direction
function getWindDirection(degrees) {
const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
// Add 22.5 to shift the range so N is centered around 0, NE around 45, etc.
const index = Math.round((degrees % 360) / 45);
return directions[index % 8];
}
// Function to determine AQI status based on European AQI scale
function getAqiStatus(aqiValue) {
if (aqiValue <= 20) {
return '<span class="text-green-400">Good</span>';
} else if (aqiValue <= 60) { // Changed from 40 to 60 to encompass "Fair" and "Moderate" into "Moderate"
return '<span class="text-yellow-400">Moderate</span>';
} else if (aqiValue <= 100) { // Changed from 80 to 100 to encompass "Poor" and "Very Poor" into "Poor"
return '<span class="text-orange-400">Poor</span>';
} else {
return '<span class="text-red-400">Bad</span>';
}
}
async function fetchWeather() {
document.getElementById('current-weather-display').classList.add('hidden');
document.getElementById('current-weather-loading').classList.remove('hidden');
document.getElementById('current-weather-error').classList.add('hidden');
document.getElementById('forecast-display').innerHTML = ''; // Clear previous forecast
document.getElementById('forecast-loading').classList.remove('hidden');
document.getElementById('forecast-error').classList.add('hidden');
try {
// Fetch current weather and 3-day forecast
// Added wind_direction_10m to the current parameters
// Changed 'precipitation' to 'precipitation_sum' in daily parameters for total daily rainfall
const weatherResponse = await fetch(`${WEATHER_API_URL}?latitude=${LATITUDE}&longitude=${LONGITUDE}¤t=temperature_2m,relative_humidity_2m,wind_speed_10m,wind_direction_10m,weather_code&daily=weather_code,temperature_2m_max,temperature_2m_min,precipitation_sum&timezone=${TIMEZONE}&forecast_days=4`);
const weatherData = await weatherResponse.json();
if (!weatherResponse.ok) {
throw new Error(weatherData.reason || 'Failed to fetch weather data');
}
const current = weatherData.current;
const daily = weatherData.daily;
// Update Current Weather
document.getElementById('current-temp').textContent = `${Math.round(current.temperature_2m)}°C`;
document.getElementById('weather-emoji').textContent = getWeatherEmoji(current.weather_code);
document.getElementById('weather-description').textContent = getWeatherDescription(current.weather_code);
// Display wind speed and direction
const windSpeedElement = document.getElementById('wind-speed');
const windDirectionElement = document.getElementById('wind-direction');
windSpeedElement.textContent = `${current.wind_speed_10m.toFixed(1)} km/h`;
windDirectionElement.textContent = getWindDirection(current.wind_direction_10m);
document.getElementById('humidity').textContent = `${current.relative_humidity_2m}%`;
// Display today's predicted total rainfall
document.getElementById('rainfall').textContent = `${daily.precipitation_sum[0].toFixed(1)} mm`;
// Call the favicon update function with the current weather code
updateFavicon(current.weather_code);
// Fetch AQI
const aqiResponse = await fetch(`${AQI_API_URL}?latitude=${LATITUDE}&longitude=${LONGITUDE}¤t=european_aqi&timezone=${TIMEZONE}`);
const aqiData = await aqiResponse.json();
const aqiElement = document.getElementById('aqi');
const aqiStatusElement = document.getElementById('aqi-status');
if (aqiResponse.ok && aqiData.current && aqiData.current.european_aqi !== undefined) {
const aqiValue = Math.round(aqiData.current.european_aqi);
aqiElement.textContent = `${aqiValue}`;
aqiStatusElement.innerHTML = getAqiStatus(aqiValue); // Use innerHTML for colored span
} else {
aqiElement.textContent = 'N/A';
aqiStatusElement.textContent = ''; // Clear status if AQI is N/A
console.warn('Could not fetch AQI data or AQI is undefined.');
}
document.getElementById('current-weather-display').classList.remove('hidden');
document.getElementById('current-weather-loading').classList.add('hidden');
// Update 3-Day Forecast
const forecastDisplay = document.getElementById('forecast-display');
forecastDisplay.innerHTML = ''; // Clear previous content
// Loop for next 3 days (index 1, 2, 3 as 0 is today)
for (let i = 1; i <= 3; i++) {
const date = new Date(daily.time[i]);
const dayName = date.toLocaleDateString('en-IN', { weekday: 'short' });
const maxTemp = Math.round(daily.temperature_2m_max[i]);
const minTemp = Math.round(daily.temperature_2m_min[i]);
const weatherCode = daily.weather_code[i];
const forecastItem = document.createElement('div');
forecastItem.className = 'weather-forecast-item';
forecastItem.innerHTML = `
<span class="font-medium text-gray-200">${dayName}</span>
<span class="text-2xl">${getWeatherEmoji(weatherCode)}</span>
<span class="text-gray-300 weather-description-text">${getWeatherDescription(weatherCode)}</span>
<span class="font-semibold text-white">${maxTemp}°C / ${minTemp}°C</span>
`;
forecastDisplay.appendChild(forecastItem);
}
document.getElementById('forecast-loading').classList.add('hidden');
} catch (error) {
console.error('Error fetching weather data:', error);
document.getElementById('current-weather-error').textContent = `Error: ${error.message}`;
document.getElementById('current-weather-error').classList.remove('hidden');
document.getElementById('current-weather-loading').classList.add('hidden');
document.getElementById('forecast-error').textContent = `Error: ${error.message}`;
document.getElementById('forecast-error').classList.remove('hidden');
document.getElementById('forecast-loading').classList.add('hidden');
}
}
// Fetch weather data every 10 minutes (600000 ms)
setInterval(fetchWeather, 600000);
</script>
</body>
</html>