diff --git a/src/SEQTA.ts b/src/SEQTA.ts
index 49582f4d..5c40a5f2 100644
--- a/src/SEQTA.ts
+++ b/src/SEQTA.ts
@@ -20,7 +20,7 @@ import { updateBgDurations } from './seqta/ui/Animation';
import { updateAllColors } from './seqta/ui/colors/Manager';
import { appendBackgroundToUI } from './seqta/ui/ImageBackgrounds';
import { enableCurrentTheme } from './seqta/ui/Themes';
-import { ObjectType } from 'typescript';
+import { info } from 'autoprefixer';
declare global {
interface Window {
@@ -1189,102 +1189,103 @@ async function AddBetterSEQTAElements(toggle: any) {
if (toggle) {
// Creates Home menu button and appends it as the first child of the list
- const result = browser.storage.local.get(['animatedbk']);
- const sliderVal = browser.storage.local.get(['bksliderinput']);
+ const result = await browser.storage.local.get();
- result.then(animbkEnable);
- sliderVal.then(updateBgDurations);
+ animbkEnable(result);
+ updateBgDurations(result);
- // Load darkmode state
- const result1 = browser.storage.local.get(['DarkMode'])
- function open (result) {
- DarkMode = result.DarkMode;
+ DarkMode = result.DarkMode;
+ if (DarkMode) {
+ document.documentElement.classList.add('dark');
}
- result1.then(open, onError)
- var titlebar = document.createElement('div');
- titlebar.classList.add('titlebar');
- let container = document.getElementById('content');
- container.append(titlebar);
- var NewButtonStr = '
';
- var NewButton = stringToHTML(NewButtonStr);
- var menu = document.getElementById('menu');
- var List = menu.firstChild;
- List.insertBefore(NewButton.firstChild, List.firstChild);
+ const container = document.getElementById('content')!;
+ container.append(document.createElement('div').classList.add('titlebar')!);
+ const NewButton = stringToHTML('');
- 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,
- }),
- })
- .then((result) => result.json())
- .then((response) => {
- let info = response.payload;
+ const menu = document.getElementById('menu')!;
+ const List = menu.firstChild! as HTMLElement;
+
+ if (NewButton.firstChild) {
+ List.insertBefore(NewButton.firstChild, List.firstChild);
+ }
- var titlebar = document.getElementsByClassName('titlebar')[0];
- titlebar.append(
- stringToHTML(
- '',
- ).firstChild,
- );
- var userinfostr = ``;
- var userinfo = stringToHTML(userinfostr).firstChild;
-
- titlebar.append(userinfo);
-
- var logoutbutton = document.getElementsByClassName('logout')[0];
- var userInfosvgdiv = document.getElementById('logouttooltip');
- userInfosvgdiv.appendChild(logoutbutton);
-
- fetch(`${location.origin}/seqta/student/load/message/people`, {
+ try {
+ // Fetch the response and wait for it
+ const response = await fetch(`${location.origin}/seqta/student/login`, {
method: 'POST',
headers: {
- 'Content-Type': 'application/json; charset=utf-8',
+ 'Content-Type': 'application/json; charset=utf-8',
+ },
+ body: JSON.stringify({
+ mode: 'normal',
+ query: null,
+ redirect_url: location.origin,
+ }),
+ });
+
+ // Parse the JSON response and wait for it
+ const responseData = await response.json();
+ let info = responseData.payload;
+
+ // Manipulate the DOM as needed
+ const titlebar = document.getElementsByClassName('titlebar')[0];
+ const userInfo = stringToHTML(
+ '',
+ ).firstChild
+ titlebar.append(userInfo!);
+
+ const userinfo = stringToHTML(``).firstChild;
+ titlebar.append(userinfo!);
+
+ var logoutbutton = document.getElementsByClassName('logout')[0];
+ var userInfosvgdiv = document.getElementById('logouttooltip')!;
+ userInfosvgdiv.appendChild(logoutbutton);
+
+ } catch (error) {
+ console.error('Error fetching and processing data:', error);
+ }
+
+ try {
+ // Await the fetch response
+ 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' }),
- })
- .then((result) => result.json())
- .then((response) => {
- let students = response.payload;
- var index = students.findIndex(function (person) {
- return (
- person.firstname == info.userDesc.split(' ')[0] &&
- person.surname == info.userDesc.split(' ')[1]
- );
- });
-
- let houseelement =
- document.getElementsByClassName('userInfohouse')[0];
- if (students[index]?.house) {
- houseelement.style.background = students[index].house_colour;
- try {
- let colorresult = GetThresholdOfColor(
- students[index]?.house_colour,
- );
-
- if (colorresult && colorresult > 300) {
- houseelement.style.color = 'black';
- } else if (colorresult < 300) {
- houseelement.style.color = 'white';
- } else {
- houseelement.style.color = 'black';
- }
- houseelement.innerText =
- students[index].year + students[index].house;
- } catch (error) {
- houseelement.innerText = students[index].house;
- }
- } else {
- houseelement.innerText = students[index].year;
- }
- });
});
+
+ // Await the JSON parsing of the response
+ const responseData = await response.json();
+ let students = responseData.payload;
+
+ // Process the students data
+ var index = students.findIndex(function (person: any) {
+ return (
+ person.firstname == info.userDesc.split(' ')[0] &&
+ person.surname == info.userDesc.split(' ')[1]
+ );
+ });
+
+ let houseelement = document.getElementsByClassName('userInfohouse')[0];
+ if (students[index]?.house) {
+ 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;
+ }
+
+ } catch (error) {
+ console.error('Error fetching and processing student data:', error);
+ }
var NewsButtonStr = '';
var NewsButton = stringToHTML(NewsButtonStr);