diff --git a/src/SEQTA.ts b/src/SEQTA.ts index 37b39729..daa40661 100644 --- a/src/SEQTA.ts +++ b/src/SEQTA.ts @@ -558,6 +558,11 @@ async function LoadPageElements(): Promise { className: 'reports', }, handleReports); + eventManager.register('timetableAdded', { + elementType: 'div', + className: 'timetablepage', + }, handleTimetable); + await handleSublink(sublink); } @@ -579,6 +584,18 @@ async function handleSublink(sublink: string | undefined): Promise { } } +async function handleTimetable(): Promise { + 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 { console.log('[BetterSEQTA+] Started Init'); if (settingsState.onoff) { @@ -1335,7 +1352,7 @@ function CheckUnmarkedAttendance(lessonattendance: any) { return lesson } -function convertTo12HourFormat(time: string): string { +function convertTo12HourFormat(time: string, noMinutes: boolean = false): string { let [hours, minutes] = time.split(':').map(Number); let period = 'AM'; @@ -1346,7 +1363,12 @@ function convertTo12HourFormat(time: string): string { 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) { diff --git a/src/css/injected.scss b/src/css/injected.scss index 54c0ef43..e06c77bd 100644 --- a/src/css/injected.scss +++ b/src/css/injected.scss @@ -1509,6 +1509,9 @@ iframe.userHTML { .dailycal > .zoom { display: none; } +.dailycal > .times > .time { + padding: 0 !important; +} .navigator { border-top-right-radius: 16px; }