fix: timetable converts to 12 hour time

This commit is contained in:
sethburkart123
2024-06-20 10:28:03 +10:00
parent d16190ce2e
commit 6dddd84467
2 changed files with 27 additions and 2 deletions
+24 -2
View File
@@ -558,6 +558,11 @@ async function LoadPageElements(): Promise<void> {
className: 'reports', className: 'reports',
}, handleReports); }, handleReports);
eventManager.register('timetableAdded', {
elementType: 'div',
className: 'timetablepage',
}, handleTimetable);
await handleSublink(sublink); await handleSublink(sublink);
} }
@@ -579,6 +584,18 @@ async function handleSublink(sublink: string | undefined): Promise<void> {
} }
} }
async function handleTimetable(): Promise<void> {
await waitForElm('.time', true, 20)
if (settingsState.timeFormat == '12') {
const times = document.querySelectorAll('.timetablepage .times .time')
for (const time of times) {
if (!time.textContent) continue
time.textContent = convertTo12HourFormat(time.textContent, true)
}
}
}
async function handleNewsPage(): Promise<void> { async function handleNewsPage(): Promise<void> {
console.log('[BetterSEQTA+] Started Init'); console.log('[BetterSEQTA+] Started Init');
if (settingsState.onoff) { if (settingsState.onoff) {
@@ -1335,7 +1352,7 @@ function CheckUnmarkedAttendance(lessonattendance: any) {
return lesson return lesson
} }
function convertTo12HourFormat(time: string): string { function convertTo12HourFormat(time: string, noMinutes: boolean = false): string {
let [hours, minutes] = time.split(':').map(Number); let [hours, minutes] = time.split(':').map(Number);
let period = 'AM'; let period = 'AM';
@@ -1346,7 +1363,12 @@ function convertTo12HourFormat(time: string): string {
hours = 12; hours = 12;
} }
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')} ${period}`; let hoursStr = hours.toString();
if (hoursStr.length === 2 && hoursStr.startsWith('0')) {
hoursStr = hoursStr.substring(1);
}
return `${hoursStr}${noMinutes ? '' : `:${minutes.toString().padStart(2, '0')}`} ${period}`;
} }
function callHomeTimetable(date: string, change?: any) { function callHomeTimetable(date: string, change?: any) {
+3
View File
@@ -1509,6 +1509,9 @@ iframe.userHTML {
.dailycal > .zoom { .dailycal > .zoom {
display: none; display: none;
} }
.dailycal > .times > .time {
padding: 0 !important;
}
.navigator { .navigator {
border-top-right-radius: 16px; border-top-right-radius: 16px;
} }