import { addExtensionSettings, enableAnimatedBackground, GetThresholdOfColor, loadHomePage, SendNewsPage, setupSettingsButton } from "../../SEQTA"; import { updateBgDurations } from "./Animation"; import { appendBackgroundToUI } from "./ImageBackgrounds"; import stringToHTML from "../utils/stringToHTML"; import { settingsState } from "../utils/listeners/SettingsState"; import { updateAllColors } from "./colors/Manager"; import { delay } from "../utils/delay"; export async function AddBetterSEQTAElements() { if (settingsState.onoff) { initializeSettings(); if (settingsState.DarkMode) { document.documentElement.classList.add('dark'); } createHomeButton(); await handleUserInfo(); handleStudentData(); createNewsButton(); setupEventListeners(); appendBackgroundToUI(); await addDarkLightToggle(); customizeMenuToggle(); } addExtensionSettings(); await createSettingsButton(); setupSettingsButton(); } function initializeSettings() { enableAnimatedBackground(); updateBgDurations(); } function createHomeButton() { const container = document.getElementById('content')!; const div = document.createElement('div'); div.classList.add('titlebar'); container.append(div); const NewButton = stringToHTML('
  • '); const menu = document.getElementById('menu')!; const List = menu.firstChild! as HTMLElement; if (NewButton.firstChild) { List.insertBefore(NewButton.firstChild, List.firstChild); } } async function handleUserInfo() { try { const info = await getUserInfo(); updateUserInfo(info); } catch (error) { console.error('Error fetching and processing student data:', error); } } function updateUserInfo(info: { basic: boolean; clientIP: string[] | null; email: string | null; id: number | null; lastAccessedTime: number | null; meta: { code: string | null; governmentID: string | null; }; personUUID: string | null; status: number | null; synergeticCommunityUrl: string | null; type: string | null; userCode: string | null; userDesc: string | null; userName: string | null; }) { const titlebar = document.getElementsByClassName('titlebar')[0]; const userInfo = stringToHTML(/* html */`
    `).firstChild; titlebar.append(userInfo!); const userinfo = stringToHTML(/* html */`

    ${info.userDesc}

    ${info.meta.code} // ${info.meta.governmentID}

    `).firstChild; titlebar.append(userinfo!); var logoutbutton = document.getElementsByClassName('logout')[0]; var userInfosvgdiv = document.getElementById('logouttooltip')!; userInfosvgdiv.appendChild(logoutbutton); } async function handleStudentData() { try { const response = await fetch(`${location.origin}/seqta/student/load/message/people`, { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: JSON.stringify({ mode: 'student' }), }); const responseData = await response.json(); let students = responseData.payload; await updateStudentInfo(students); } catch (error) { console.error('Error fetching and processing student data:', error); } } async function getUserInfo() { try { const response = await fetch(`${location.origin}/seqta/student/login`, { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: JSON.stringify({ mode: 'normal', query: null, redirect_url: location.origin, }), }); const responseData = await response.json(); return responseData.payload; } catch (error) { console.error('Error fetching user info:', error); throw error; // Rethrow the error after logging it } } async function updateStudentInfo(students: any) { const info = await getUserInfo(); // You would need to implement this to fetch or pass the user info var index = students.findIndex(function (person: any) { return ( person.firstname == info.userDesc.split(' ')[0] && person.surname == info.userDesc.split(' ')[1] ); }); let houseelement1 = document.getElementsByClassName('userInfohouse')[0]; const houseelement = houseelement1 as HTMLElement; if (students[index]?.house) { if (students[index]?.house_colour) { houseelement.style.background = students[index].house_colour; try { let colorresult = GetThresholdOfColor(students[index]?.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; } } } else { houseelement.innerText = students[index].year; } } function createNewsButton() { const NewsButtonStr = '
  • '; const NewsButton = stringToHTML(NewsButtonStr); const menu = document.getElementById('menu')!; const List = menu.firstChild! as HTMLElement; List!.appendChild(NewsButton.firstChild!); let a = document.createElement('div'); a.classList.add('icon-cover'); a.id = 'icon-cover'; menu!.appendChild(a); } function setupEventListeners() { const menuCover = document.querySelector('#icon-cover'); menuCover!.addEventListener('click', function () { location.href = '../#?page=/home'; loadHomePage(); (document!.getElementById('menu')!.firstChild! as HTMLElement).classList.remove('noscroll'); }); const homebutton = document.getElementById('homebutton'); homebutton!.addEventListener('click', function () { if (!homebutton?.classList.contains('draggable') && !homebutton?.classList.contains('active')) { loadHomePage(); } }); const newsbutton = document.getElementById('newsbutton'); newsbutton!.addEventListener('click', function () { if (!newsbutton?.classList.contains('draggable') && !newsbutton?.classList.contains('active')) { SendNewsPage(); } }); } async function createSettingsButton() { let SettingsButton = stringToHTML( /* html */` `); let ContentDiv = document.getElementById('content'); ContentDiv!.append(SettingsButton.firstChild!); } function GetLightDarkModeString() { if (settingsState.DarkMode) { return 'Switch to light theme' } else { return 'Switch to dark theme' } } async function addDarkLightToggle() { const tooltipString = GetLightDarkModeString(); const svgContent = settingsState.DarkMode ? /* html */`` : /* html */``; const LightDarkModeButton = stringToHTML(/* html */` `); let ContentDiv = document.getElementById('content'); ContentDiv!.append(LightDarkModeButton.firstChild!); updateAllColors(); document.getElementById('LightDarkModeButton')!.addEventListener('click', async () => { const darklightText = document.getElementById('darklighttooliptext'); if (settingsState.originalDarkMode != undefined) { darklightText!.innerText = 'Locked by current theme'; await delay(1000) darklightText!.innerText = GetLightDarkModeString(); return } settingsState.DarkMode = !settingsState.DarkMode; updateAllColors(); darklightText!.innerText = GetLightDarkModeString(); }); } function customizeMenuToggle() { const menuToggle = document.getElementById('menuToggle'); if (menuToggle) { menuToggle.innerHTML = ''; } for (let i = 0; i < 3; i++) { const line = document.createElement('div'); line.className = 'hamburger-line'; menuToggle!.appendChild(line); } }