-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusic.html
More file actions
452 lines (408 loc) · 24 KB
/
music.html
File metadata and controls
452 lines (408 loc) · 24 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Data | Daniel Han</title>
<link rel="icon" type="image/png" href="images/f1zzyicon.png">
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.music-container { max-width: 1500px; margin: 0 auto; width: 95%; padding-top: 120px; padding-bottom: 50px;}
.music-grid { display: grid; grid-template-columns: 350px 1fr; gap: 2rem; margin-top: 2rem; align-items: start; }
.panel {
background: rgba(20, 20, 20, 0.6); border: 1px solid rgba(0, 255, 65, 0.2);
padding: 1.5rem; border-radius: 8px; backdrop-filter: blur(10px);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(0, 255, 65, 0.05);
position: relative; margin-bottom: 1.5rem;
}
.panel-title { color: var(--accent); font-size: 1.0rem; border-bottom: 1px dashed rgba(0, 255, 65, 0.3); padding-bottom: 0.5rem; margin-bottom: 1.5rem; text-transform: uppercase; letter-spacing: 1px; display: flex; justify-content: space-between; align-items: center; }
.time-controls { display: flex; gap: 10px; margin-bottom: 1.5rem; flex-wrap: wrap; }
.time-btn, .sort-btn {
background: transparent; color: var(--text-secondary); border: 1px solid rgba(255,255,255,0.2);
padding: 6px 12px; font-family: var(--font-mono); font-size: 0.8rem; cursor: pointer; border-radius: 4px; transition: 0.2s;
}
.time-btn.active, .time-btn:hover, .sort-btn.active, .sort-btn:hover { background: rgba(0, 255, 65, 0.1); color: var(--accent); border-color: var(--accent); }
.panel-sort-controls { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.sort-btn { padding: 2px 6px; font-size: 0.65rem; }
.total-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 0.5rem; }
.stat-box { background: rgba(0,0,0,0.3); padding: 12px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.05); display: flex; flex-direction: column; align-items: center; }
.stat-label { color: var(--text-secondary); font-size: 0.65rem; text-transform: uppercase; margin-bottom: 4px; }
.stat-val { color: #fff; font-size: 1.2rem; font-weight: bold; font-family: var(--font-mono); }
.now-playing { display: flex; gap: 1rem; align-items: center; background: rgba(0, 255, 65, 0.05); padding: 1rem; border-radius: 6px; border: 1px solid rgba(0, 255, 65, 0.2); margin-bottom: 1rem; }
.now-playing img { width: 50px; height: 50px; border-radius: 4px; object-fit: cover;}
.np-info { display: flex; flex-direction: column; gap: 2px; width: 100%; overflow: hidden;}
.np-status { color: var(--accent); font-size: 0.65rem; font-weight: bold; display: flex; align-items: center; gap: 5px; }
.np-title { color: #fff; font-size: 0.85rem; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { color: var(--text-secondary); font-size: 0.75rem; }
.eq { display: flex; gap: 2px; height: 8px; align-items: flex-end; }
.eq-bar { width: 2px; background: var(--accent); animation: eq 0.6s infinite alternate; }
@keyframes eq { 0% { height: 2px; } 100% { height: 8px; } }
.history-log { background: #050505; border: 1px solid #222; padding: 1rem; border-radius: 6px; height: 250px; overflow-y: auto; font-size: 0.75rem; display: flex; flex-direction: column; gap: 8px; }
.history-log::-webkit-scrollbar { width: 4px; }
.history-log::-webkit-scrollbar-thumb { background: rgba(0,255,65,0.3); }
.log-item { display: flex; gap: 8px; border-bottom: 1px dashed #1a1a1a; padding-bottom: 6px; }
.log-time { color: var(--accent-blue); flex-shrink: 0; font-size: 0.7rem; }
.log-data { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}
.log-data span { color: #fff; }
.data-row { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-bottom: 2rem; }
.track-list { display: flex; flex-direction: column; gap: 12px; }
.top-track-item { display: flex; align-items: center; gap: 15px; }
.track-rank { color: var(--accent); font-weight: bold; width: 20px; font-size: 0.9rem; }
.track-core { flex-grow: 1; display: flex; flex-direction: column; gap: 4px; }
.track-name-row { display: flex; justify-content: space-between; font-size: 0.85rem; }
.track-name-row .t-name { color: #fff; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-name-row .t-plays { color: var(--text-secondary); }
.play-bar-bg { width: 100%; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.play-bar-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.albums-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 15px; }
.album-card { position: relative; aspect-ratio: 1/1; border-radius: 4px; overflow: hidden; border: 1px solid rgba(255,255,255,0.1); }
.album-card img { width: 100%; height: 100%; object-fit: cover; transition: 0.3s; }
.album-overlay { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.8); padding: 5px; transform: translateY(100%); transition: 0.3s; display: flex; flex-direction: column; }
.album-card:hover img { transform: scale(1.05); filter: brightness(0.5); }
.album-card:hover .album-overlay { transform: translateY(0); }
.a-name { color: #fff; font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.a-plays { color: var(--accent); font-size: 0.65rem; }
.scraper-status { color: #ffbd2e; font-size: 0.85rem; text-align: center; margin-bottom: 1rem; animation: pulse 1.5s infinite; min-height: 20px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.methodology-note { color: var(--text-secondary); font-size: 0.65rem; margin-top: 10px; font-family: var(--font-mono); text-align: right; }
@media(max-width: 1100px) {
.music-grid, .data-row { grid-template-columns: 1fr; }
}
</style>
</head>
<body class="loading">
<div class="grid-bg"></div>
<nav class="nav">
<div class="nav-container">
<a href="index.html"><div class="nav-logo nav-glitch" data-text="> Daniel Han">> Daniel Han</div></a>
<div class="nav-links">
<a href="index.html#about" class="hacker-text" data-value="About">About</a>
<a href="index.html#education" class="hacker-text" data-value="Education">Education</a>
<a href="index.html#experience" class="hacker-text" data-value="Experience">Experience</a>
<a href="blog.html" class="hacker-text" data-value="Blog">Blog</a>
<a href="misc.html" class="hacker-text" data-value="Misc">Misc</a>
<a href="music.html" class="hacker-text active" data-value="Music">Music</a>
</div>
</div>
</nav>
<div class="music-container">
<h2 class="section-title hacker-text" data-value="> Judge My Music Taste">> Judge My Music Taste</h2>
<p style="color: var(--text-secondary); margin-bottom: 2rem;">Real-time listening Spotify data feed powered by Last.fm</p>
<div class="time-controls" id="time-controls">
<button class="time-btn active" data-period="7day">7 Days</button>
<button class="time-btn" data-period="1month">1 Month</button>
<button class="time-btn" data-period="12month">1 Year</button>
<button class="time-btn" data-period="overall">All Time</button>
</div>
<div class="music-grid">
<div class="left-col">
<div class="panel">
<h3 class="panel-title">Total Stats</h3>
<div class="total-stats-grid">
<div class="stat-box">
<span class="stat-label">Songs Played</span>
<span class="stat-val" id="total-scrobbles">--</span>
</div>
<div class="stat-box">
<span class="stat-label">Artists Discovered</span>
<span class="stat-val" id="artist-count">--</span>
</div>
</div>
</div>
<div class="panel">
<h3 class="panel-title">Music Logs</h3>
<div class="now-playing" id="now-playing">
<img src="images/f1zzyicon.png" id="np-img" alt="Art">
<div class="np-info">
<div class="np-status" id="np-status">INITIALIZING...</div>
<div class="np-title" id="np-title">--</div>
<div class="np-artist" id="np-artist">--</div>
</div>
</div>
<div class="history-log" id="history-log">
</div>
</div>
<div class="panel">
<h3 class="panel-title">Listening Clock</h3>
<div style="height: 300px; width: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center;">
<canvas id="clockChart"></canvas>
<p class="methodology-note">*Note: This is a sample based on the most recent 2,000 tracks.</p>
</div>
</div>
</div>
<div class="right-col">
<div class="data-row">
<div class="panel">
<h3 class="panel-title" id="top-tracks-title">Top Tracks (7 Days)</h3>
<div class="track-list" id="top-tracks">
</div>
</div>
<div class="panel">
<h3 class="panel-title" id="artist-radar-title">Artist Radar (7 Days)</h3>
<div style="height: 300px; width: 100%; display: flex; justify-content: center;">
<canvas id="artistRadarChart"></canvas>
</div>
</div>
</div>
<div class="panel">
<h3 class="panel-title" id="top-albums-title">Heavy Rotation (Albums)</h3>
<div class="albums-grid" id="top-albums">
</div>
</div>
<div id="deep-data-status" class="scraper-status">INITIATING DEEP TELEMETRY SCRAPE...</div>
<div class="panel">
<div class="panel-title">
<span>Historical Listening Volume</span>
<div class="panel-sort-controls">
<button class="sort-btn active" data-sort="12m">12M</button>
<button class="sort-btn" data-sort="2026">2026</button>
<button class="sort-btn" data-sort="2025">2025</button>
<button class="sort-btn" data-sort="2024">2024</button>
<button class="sort-btn" data-sort="2023">2023</button>
<button class="sort-btn" data-sort="2022">2022</button>
<button class="sort-btn" data-sort="2021">2021</button>
<button class="sort-btn" data-sort="all">ALL</button>
</div>
</div>
<div style="height: 450px; width: 100%;">
<canvas id="monthlyChart"></canvas>
</div>
</div>
</div>
</div>
</div>
<script>
// ==========================================
// LAST.FM TELEMETRY CORE
// ==========================================
const API_KEY = '6428cc31e6ba1fb7fa52fc69ff008d05';
const USERNAME = 'f1zzy22222';
const BASE_URL = `https://ws.audioscrobbler.com/2.0/?user=${USERNAME}&api_key=${API_KEY}&format=json`;
let radarChartInstance, clockChartInstance, monthlyChartInstance;
let registrationTime = 0;
async function fetchAPI(method, extraParams = '') {
try {
const res = await fetch(`${BASE_URL}&method=${method}${extraParams}`);
if(!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
return await res.json();
} catch (e) {
console.error(`Last.fm API Error (${method}):`, e);
return null;
}
}
function timeAgo(unixTimestamp) {
if (!unixTimestamp) return 'UNKNOWN';
const seconds = Math.floor(Date.now() / 1000) - unixTimestamp;
if (seconds < 60) return `${seconds}s ago`;
if (seconds < 3600) return `${Math.floor(seconds/60)}m ago`;
if (seconds < 86400) return `${Math.floor(seconds/3600)}h ago`;
return `${Math.floor(seconds/86400)}d ago`;
}
function getSafeImage(item) {
if (item && item.image && Array.isArray(item.image)) {
const imgObj = item.image[3] || item.image[2] || item.image[1] || item.image[0];
if (imgObj && imgObj['#text']) return imgObj['#text'];
}
return 'images/f1zzyicon.png';
}
async function loadLiveFeed() {
const data = await fetchAPI('user.getrecenttracks', '&limit=25');
if (!data || !data.recenttracks) return;
const info = await fetchAPI('user.getinfo');
if(info && info.user) {
document.getElementById('total-scrobbles').innerText = parseInt(info.user.playcount || 0).toLocaleString();
document.getElementById('artist-count').innerText = parseInt(info.user.artist_count || 0).toLocaleString();
registrationTime = parseInt(info.user.registered.unixtime);
}
let tracks = data.recenttracks.track;
if (!Array.isArray(tracks)) tracks = [tracks];
const np = tracks[0];
const isPlaying = np['@attr'] && np['@attr'].nowplaying === 'true';
document.getElementById('np-title').innerText = np.name || 'Unknown Track';
document.getElementById('np-artist').innerText = (np.artist && np.artist['#text']) ? np.artist['#text'] : 'Unknown Artist';
document.getElementById('np-img').src = getSafeImage(np);
document.getElementById('np-status').innerHTML = isPlaying
? `<div class="eq"><div class="eq-bar"></div><div class="eq-bar"></div><div class="eq-bar"></div></div> ONLINE (LIVE LISTENING)`
: `OFFLINE (LAST LISTENED)`;
const logHtml = tracks.map(t => {
const isLive = t['@attr'] && t['@attr'].nowplaying === 'true';
const timeStr = isLive ? 'LIVE' : timeAgo(t.date ? t.date.uts : null);
return `<div class="log-item"><div class="log-time">[${timeStr}]</div><div class="log-data"><span>${t.artist['#text']}</span> - ${t.name}</div></div>`;
}).join('');
document.getElementById('history-log').innerHTML = logHtml;
}
async function loadHistoricalMonthlyData(viewType = '12m') {
const monthlyCounts = {};
const now = new Date();
const statusEl = document.getElementById('deep-data-status');
statusEl.style.display = 'block';
statusEl.innerText = `SCRAPING HISTORICAL TOTALS [${viewType.toUpperCase()}]...`;
let loopCount = 12;
let baseDate = new Date();
if (viewType === 'all') {
const regDate = new Date(registrationTime * 1000);
loopCount = (now.getFullYear() - regDate.getFullYear()) * 12 + (now.getMonth() - regDate.getMonth()) + 1;
loopCount = Math.min(loopCount, 120);
} else if (viewType === '2026') {
loopCount = now.getMonth() + 1;
} else if (viewType.length === 4) {
const targetYear = parseInt(viewType);
loopCount = 12;
baseDate = new Date(targetYear, 11, 31);
}
for (let i = 0; i < loopCount; i++) {
const currentMonthStart = new Date(baseDate.getFullYear(), baseDate.getMonth() - i, 1);
const currentMonthEnd = new Date(baseDate.getFullYear(), baseDate.getMonth() - i + 1, 0, 23, 59, 59);
const fromTs = Math.floor(currentMonthStart.getTime() / 1000);
const toTs = Math.floor(currentMonthEnd.getTime() / 1000);
const data = await fetchAPI('user.getrecenttracks', `&from=${fromTs}&to=${toTs}&limit=1`);
if (data && data.recenttracks && data.recenttracks['@attr']) {
const label = currentMonthStart.toLocaleString('en-US', { month: 'short', year: 'numeric' });
monthlyCounts[label] = parseInt(data.recenttracks['@attr'].total);
}
await new Promise(r => setTimeout(r, 80));
}
renderMonthlyChart(monthlyCounts);
statusEl.style.display = 'none';
}
async function loadDeepAnalytics() {
let allTracks = [];
try {
for(let i=1; i<=10; i++) {
const data = await fetchAPI('user.getrecenttracks', `&limit=200&page=${i}`);
if(data && data.recenttracks && data.recenttracks.track) {
allTracks.push(...(Array.isArray(data.recenttracks.track) ? data.recenttracks.track : [data.recenttracks.track]));
}
await new Promise(r => setTimeout(r, 100));
}
const hourlyCounts = new Array(24).fill(0);
allTracks.forEach(track => {
if (track.date && track.date.uts) {
const date = new Date(track.date.uts * 1000);
hourlyCounts[date.getHours()]++;
}
});
renderClockChart(hourlyCounts);
} catch(e) { console.error(e); }
}
function renderMonthlyChart(monthlyCounts) {
if(monthlyChartInstance) monthlyChartInstance.destroy();
const ctx = document.getElementById('monthlyChart').getContext('2d');
const labels = Object.keys(monthlyCounts).reverse();
const dataPts = Object.values(monthlyCounts).reverse();
monthlyChartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{ label: 'Plays', data: dataPts, backgroundColor: 'rgba(0, 255, 65, 0.4)', borderColor: '#00ff41', borderWidth: 1, borderRadius: 4 }]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: { grid: { color: 'rgba(255,255,255,0.05)' }, ticks: { color: '#888', font: { family: 'JetBrains Mono', size: 10 } } },
y: { grid: { display: true, color: 'rgba(255,255,255,0.05)' }, ticks: { color: '#e0e0e0', font: { family: 'JetBrains Mono', size: 11 } } }
}
}
});
}
function renderClockChart(hourlyCounts) {
if(clockChartInstance) clockChartInstance.destroy();
const ctx = document.getElementById('clockChart').getContext('2d');
const labels = Array.from({length: 24}, (_, i) => {
const period = i >= 12 ? 'PM' : 'AM';
const hour = i % 12 || 12;
return `${hour}${period}`;
});
clockChartInstance = new Chart(ctx, {
type: 'polarArea',
data: { labels: labels, datasets: [{ data: hourlyCounts, backgroundColor: 'rgba(0, 212, 255, 0.5)', borderColor: 'rgba(20,20,20,1)', borderWidth: 1 }] },
options: {
responsive: true, maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: function(context) {
return ` ${context.raw} plays`;
}
}
}
},
scales: { r: { ticks: {display: false}, grid: {color: 'rgba(255,255,255,0.05)'} } }
}
});
}
async function loadPeriodicData(period) {
const periodLabel = period === '7day' ? '7 Days' : period === '1month' ? '1 Month' : period === '12month' ? '1 Year' : 'All Time';
document.getElementById('top-tracks-title').innerText = `Top Tracks (${periodLabel})`;
document.getElementById('artist-radar-title').innerText = `Artist Radar (${periodLabel})`;
const tracksData = await fetchAPI('user.gettoptracks', `&limit=6&period=${period}`);
if(tracksData && tracksData.toptracks && tracksData.toptracks.track) {
const tracks = Array.isArray(tracksData.toptracks.track) ? tracksData.toptracks.track : [tracksData.toptracks.track];
const maxPlays = Math.max(...tracks.map(t => parseInt(t.playcount || 0)));
document.getElementById('top-tracks').innerHTML = tracks.map((t, i) => {
const plays = parseInt(t.playcount || 0);
const pct = maxPlays > 0 ? (plays / maxPlays) * 100 : 0;
return `<div class="top-track-item"><div class="track-rank">0${i+1}</div><div class="track-core"><div class="track-name-row"><span class="t-name">${t.name}</span><span class="t-plays">${plays} plays</span></div><div class="play-bar-bg"><div class="play-bar-fill" style="width: ${pct}%"></div></div></div></div>`;
}).join('');
}
const albumsData = await fetchAPI('user.gettopalbums', `&limit=10&period=${period}`);
if(albumsData && albumsData.topalbums && albumsData.topalbums.album) {
const albums = Array.isArray(albumsData.topalbums.album) ? albumsData.topalbums.album : [albumsData.topalbums.album];
document.getElementById('top-albums').innerHTML = albums.map(a => `<div class="album-card"><img src="${getSafeImage(a)}" alt="${a.name}"><div class="album-overlay"><span class="a-name">${a.name}</span><span class="a-plays">${a.playcount} plays</span></div></div>`).join('');
}
const artistsData = await fetchAPI('user.gettopartists', `&limit=6&period=${period}`);
if(artistsData && artistsData.topartists && artistsData.topartists.artist) {
const artists = Array.isArray(artistsData.topartists.artist) ? artistsData.topartists.artist : [artistsData.topartists.artist];
if(radarChartInstance) radarChartInstance.destroy();
radarChartInstance = new Chart(document.getElementById('artistRadarChart').getContext('2d'), {
type: 'polarArea',
data: { labels: artists.map(a => a.name), datasets: [{ data: artists.map(a => parseInt(a.playcount)), backgroundColor: ['rgba(0, 255, 65, 0.6)', 'rgba(0, 212, 255, 0.6)', 'rgba(255, 0, 193, 0.6)', 'rgba(255, 215, 0, 0.6)', 'rgba(255, 77, 77, 0.6)', 'rgba(153, 51, 255, 0.6)'], borderColor: 'rgba(20,20,20,1)', borderWidth: 2 }] },
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { position: 'right', labels: { color: '#888', font: {family: 'JetBrains Mono', size: 10} } },
tooltip: {
callbacks: {
label: function(context) {
return ` ${context.raw} plays`;
}
}
}
},
scales: { r: { ticks: {display: false}, grid: {color: 'rgba(255,255,255,0.1)'} } }
}
});
}
}
document.addEventListener('DOMContentLoaded', () => {
document.body.classList.remove('loading');
if(API_KEY === 'YOUR_LASTFM_API_KEY') return;
loadLiveFeed();
loadDeepAnalytics();
loadHistoricalMonthlyData('12m');
loadPeriodicData('7day');
setInterval(loadLiveFeed, 30000);
document.querySelectorAll('.time-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.time-btn').forEach(b => b.classList.remove('active'));
e.target.classList.add('active');
loadPeriodicData(e.target.getAttribute('data-period'));
});
});
document.querySelectorAll('.sort-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.sort-btn').forEach(b => b.classList.remove('active'));
e.target.classList.add('active');
loadHistoricalMonthlyData(e.target.getAttribute('data-sort'));
});
});
});
</script>
<script src="script.js"></script>
</body>
</html>