From e0cc2e0fdf5b63eca25a181fec73ff83b4468998 Mon Sep 17 00:00:00 2001 From: Jaxon Lewis-Wilson Date: Sun, 18 Jan 2026 00:11:09 +0800 Subject: [PATCH] fix: House/year box hard failing when house_colour does not exist --- src/seqta/ui/AddBetterSEQTAElements.ts | 37 +++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/seqta/ui/AddBetterSEQTAElements.ts b/src/seqta/ui/AddBetterSEQTAElements.ts index 0498b9a7..e7b5df62 100644 --- a/src/seqta/ui/AddBetterSEQTAElements.ts +++ b/src/seqta/ui/AddBetterSEQTAElements.ts @@ -173,28 +173,35 @@ async function updateStudentInfo(students: any) { ); }); - let houseelement1 = document.getElementsByClassName("userInfohouse")[0]; - const houseelement = houseelement1 as HTMLElement; + const houseelement = document.getElementsByClassName("userInfohouse")[0] as HTMLElement; + + // Fallback to N/A + let text = 'N/A'; + const student = students[index] ?? {}; + + // If student has a house, prefer to show year + house. If no year, only show house. + if (student.house) { + text = `${student.year ?? ""}${student.house}`; + + // If house_colour exists, compute colour + if (student.house_colour) { + houseelement.style.background = student.house_colour; - if (students[index]?.house) { - if (students[index]?.house_colour) { - houseelement.style.background = students[index].house_colour; try { - let colorresult = GetThresholdOfColor(students[index]?.house_colour); + const colorresult = GetThresholdOfColor(student.house_colour); houseelement.style.color = colorresult && colorresult > 300 ? "black" : "white"; - houseelement.innerText = students[index].year + students[index].house; - } catch (error) { - houseelement.innerText = students[index].house; + + } catch (err) { + // Colour calculation failed, no text colour set } } - } else { - try { - houseelement.innerText = students[index].year; - } catch (err) { - houseelement.innerText = "N/A"; - } + } else if (student.year) { + // No house, only year will be shown + text = student.year; } + + houseelement.innerText = text; } function createNewsButton(fragment: DocumentFragment, menu: HTMLElement) {