Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (63 loc) · 2.15 KB
/
Copy pathapp.js
File metadata and controls
73 lines (63 loc) · 2.15 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
(async () => {
const applyColors = (colors) => {
if (!colors?.length) return;
const valid = colors.filter((c) => {
const el = document.createElement('div');
el.style.backgroundColor = c;
return el.style.backgroundColor !== '';
});
if (!valid.length) return;
const positions =
valid.length === 1
? ['50% 50%']
: valid.length === 2
? ['30% 50%', '70% 50%']
: ['20% 50%', '50% 50%', '80% 50%'];
const size = valid.length === 1 ? '100% 80%' : '70% 80%';
document.body.style.backgroundImage = valid
.slice(0, 3)
.map(
(c, i) =>
`radial-gradient(ellipse ${size} at ${positions[i]}, color-mix(in srgb, ${c} 25%, transparent) 0%, transparent 70%)`
)
.join(', ');
};
const show = (id) => {
document.querySelectorAll('.state').forEach((el) => (el.hidden = true));
document.getElementById(id).hidden = false;
};
const fmtDate = (iso) =>
new Date(iso).toLocaleDateString('en-US', {
month: 'long',
day: 'numeric',
year: 'numeric',
timeZone: 'America/New_York',
});
try {
// Cache-bust so GitHub Pages CDN doesn't serve stale data.json
const res = await fetch(`data.json?v=${Date.now()}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
const genEl = document.getElementById('generated-at');
if (genEl && data.generated_at) {
genEl.textContent = `Last updated: ${new Date(data.generated_at).toLocaleString('en-US', {
dateStyle: 'medium',
timeStyle: 'short',
timeZone: 'America/New_York',
})} ET`;
}
if (data.has_event && data.event) {
document.getElementById('event-purpose').textContent = data.event.purpose;
document.getElementById('event-date').textContent =
`${fmtDate(data.event.start)} – ${fmtDate(data.event.end)}`;
document.title = `${data.event.purpose} | Prudential Center Lights Tonight`;
show('event');
applyColors(data.colors);
} else {
show('no-event');
}
} catch (err) {
console.error('Failed to load data.json:', err);
show('error');
}
})();