-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
96 lines (82 loc) · 3.57 KB
/
Copy pathscript.js
File metadata and controls
96 lines (82 loc) · 3.57 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
class ScheduleManager {
constructor() {
this.dataRoot = '../LHS-Connect-Beta-Data';
this.currentSchedule = null;
this.init();
}
async init() {
this.updateClock();
setInterval(() => this.updateClock(), 1000);
await this.loadAndDisplaySchedule();
}
formatTime(timeString) {
const [hour, minute] = timeString.split(':');
const h = parseInt(hour, 10);
const m = minute;
const ampm = h >= 12 ? 'PM' : 'AM';
const formattedHour = h % 12 || 12;
return `${formattedHour}:${m} ${ampm}`;
}
getCurrentPeriod(schedule) {
const now = new Date();
const currentTime = now.getHours() * 60 + now.getMinutes();
return schedule.periods.find(p => {
const [sH, sM] = p.startTime.split(':').map(Number);
const [eH, eM] = p.endTime.split(':').map(Number);
const start = sH * 60 + sM;
const end = eH * 60 + eM;
return currentTime >= start && currentTime < end;
});
}
updateClock() {
const now = new Date();
document.getElementById('current-date').textContent = now.toLocaleDateString();
document.getElementById('current-time').textContent = now.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit', second: '2-digit' });
if (this.currentSchedule) {
const period = this.getCurrentPeriod(this.currentSchedule);
const titleEl = document.getElementById('page-title');
if (period) {
const [eH, eM] = period.endTime.split(':').map(Number);
const endSeconds = eH * 3600 + eM * 60;
const nowSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
const remainingSeconds = endSeconds - nowSeconds;
const remainingMinutes = Math.floor(remainingSeconds / 60);
const remainingSecs = remainingSeconds % 60;
titleEl.textContent = `${remainingMinutes}m ${remainingSecs}s left in ${period.periodName}`;
document.title = titleEl.textContent;
} else {
titleEl.textContent = "LHS Connect Beta";
document.title = titleEl.textContent;
}
}
}
async fetchJson(path) {
const response = await fetch(path);
return await response.json();
}
async loadAndDisplaySchedule() {
const now = new Date();
const dateKey = now.toISOString().split('T')[0];
const dayOfWeek = now.toLocaleDateString('en-US', { weekday: 'short' }).toLowerCase();
try {
const [normalMapping, overrides] = await Promise.all([
this.fetchJson(`${this.dataRoot}/normal_schedule_mapping.json`),
this.fetchJson(`${this.dataRoot}/overrides.json`)
]);
const schedulePath = overrides[dateKey] || normalMapping[dayOfWeek];
this.currentSchedule = await this.fetchJson(`${this.dataRoot}/${schedulePath}`);
this.displaySchedule(this.currentSchedule);
} catch (error) {
console.error("Failed to load schedule:", error);
}
}
displaySchedule(schedule) {
const list = document.getElementById('schedule-list');
list.innerHTML = schedule.periods.map(p => `
<li>
<strong>${p.periodName}</strong>: ${this.formatTime(p.startTime)} - ${this.formatTime(p.endTime)}
</li>
`).join('');
}
}
document.addEventListener('DOMContentLoaded', () => new ScheduleManager());