import { addExtensionSettings, enableAnimatedBackground, GetThresholdOfColor, loadHomePage, SendNewsPage, setupSettingsButton } from "@/SEQTA"; import { updateBgDurations } from "./Animation"; import { appendBackgroundToUI } from "./ImageBackgrounds"; import stringToHTML from "@/seqta/utils/stringToHTML"; import { settingsState } from "@/seqta/utils/listeners/SettingsState"; import { updateAllColors } from "./colors/Manager"; import { delay } from "@/seqta/utils/delay"; let cachedUserInfo: any = null; async function getUserInfo() { if (cachedUserInfo) return cachedUserInfo; 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(); cachedUserInfo = responseData.payload; return cachedUserInfo; } catch (error) { console.error('Error fetching user info:', error); throw error; } } export async function AddBetterSEQTAElements() { if (settingsState.onoff) { initializeSettings(); if (settingsState.DarkMode) { document.documentElement.classList.add('dark'); } const fragment = document.createDocumentFragment(); const menu = document.getElementById('menu')!; const menuList = menu.firstChild as HTMLElement; createHomeButton(fragment, menuList); createNewsButton(fragment, menu); menuList.insertBefore(fragment, menuList.firstChild); try { await Promise.all([ appendBackgroundToUI(), handleUserInfo(), handleStudentData() ]); } catch (error) { console.error('Error initializing UI elements:', error); } setupEventListeners(); await addDarkLightToggle(); customizeMenuToggle(); } addExtensionSettings(); await createSettingsButton(); setupSettingsButton(); } function initializeSettings() { enableAnimatedBackground(); updateBgDurations(); } function createHomeButton(fragment: DocumentFragment, menuList: HTMLElement) { const container = document.getElementById('content')!; const div = document.createElement('div'); div.classList.add('titlebar'); container.append(div); const NewButton = stringToHTML('
'); if (NewButton.firstChild) { fragment.appendChild(NewButton.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 */`${info.userDesc}
${info.meta.code} // ${info.meta.governmentID}