more typescript conversion

This commit is contained in:
SethBurkart123
2023-12-04 21:39:38 +11:00
parent 35bad217b4
commit 0983ef16a1
+54 -53
View File
@@ -20,7 +20,7 @@ import { updateBgDurations } from './seqta/ui/Animation';
import { updateAllColors } from './seqta/ui/colors/Manager'; import { updateAllColors } from './seqta/ui/colors/Manager';
import { appendBackgroundToUI } from './seqta/ui/ImageBackgrounds'; import { appendBackgroundToUI } from './seqta/ui/ImageBackgrounds';
import { enableCurrentTheme } from './seqta/ui/Themes'; import { enableCurrentTheme } from './seqta/ui/Themes';
import { ObjectType } from 'typescript'; import { info } from 'autoprefixer';
declare global { declare global {
interface Window { interface Window {
@@ -1189,30 +1189,30 @@ async function AddBetterSEQTAElements(toggle: any) {
if (toggle) { if (toggle) {
// Creates Home menu button and appends it as the first child of the list // Creates Home menu button and appends it as the first child of the list
const result = browser.storage.local.get(['animatedbk']); const result = await browser.storage.local.get();
const sliderVal = browser.storage.local.get(['bksliderinput']);
result.then(animbkEnable); animbkEnable(result);
sliderVal.then(updateBgDurations); 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'); const container = document.getElementById('content')!;
titlebar.classList.add('titlebar'); container.append(document.createElement('div').classList.add('titlebar')!);
let container = document.getElementById('content'); const NewButton = stringToHTML('<li class="item" data-key="home" id="homebutton" data-path="/home" data-betterseqta="true"><label><svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z" /></svg><span>Home</span></label></li>');
container.append(titlebar);
var NewButtonStr = '<li class="item" data-key="home" id="homebutton" data-path="/home" data-betterseqta="true"><label><svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z" /></svg><span>Home</span></label></li>'; const menu = document.getElementById('menu')!;
var NewButton = stringToHTML(NewButtonStr); const List = menu.firstChild! as HTMLElement;
var menu = document.getElementById('menu');
var List = menu.firstChild; if (NewButton.firstChild) {
List.insertBefore(NewButton.firstChild, List.firstChild); List.insertBefore(NewButton.firstChild, List.firstChild);
}
fetch(`${location.origin}/seqta/student/login`, { try {
// Fetch the response and wait for it
const response = await fetch(`${location.origin}/seqta/student/login`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
@@ -1222,69 +1222,70 @@ async function AddBetterSEQTAElements(toggle: any) {
query: null, query: null,
redirect_url: location.origin, redirect_url: location.origin,
}), }),
}) });
.then((result) => result.json())
.then((response) => {
let info = response.payload;
var titlebar = document.getElementsByClassName('titlebar')[0]; // Parse the JSON response and wait for it
titlebar.append( const responseData = await response.json();
stringToHTML( let info = responseData.payload;
// Manipulate the DOM as needed
const titlebar = document.getElementsByClassName('titlebar')[0];
const userInfo = stringToHTML(
'<div class="userInfosvgdiv tooltip"><svg class="userInfosvg" viewBox="0 0 24 24"><path fill="var(--text-primary)" d="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></path></svg><div class="tooltiptext topmenutooltip" id="logouttooltip"></div></div>', '<div class="userInfosvgdiv tooltip"><svg class="userInfosvg" viewBox="0 0 24 24"><path fill="var(--text-primary)" d="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></path></svg><div class="tooltiptext topmenutooltip" id="logouttooltip"></div></div>',
).firstChild, ).firstChild
); titlebar.append(userInfo!);
var userinfostr = `<div class="userInfo"><div class="userInfoText"><div style="display: flex; align-items: center;"><p class="userInfohouse userInfoCode"></p><p class="userInfoName">${info.userDesc}</p></div><p class="userInfoCode">${UserInitalCode}</p></div></div>`;
var userinfo = stringToHTML(userinfostr).firstChild;
titlebar.append(userinfo); const userinfo = stringToHTML(`<div class="userInfo"><div class="userInfoText"><div style="display: flex; align-items: center;"><p class="userInfohouse userInfoCode"></p><p class="userInfoName">${info.userDesc}</p></div><p class="userInfoCode">${UserInitalCode}</p></div></div>`).firstChild;
titlebar.append(userinfo!);
var logoutbutton = document.getElementsByClassName('logout')[0]; var logoutbutton = document.getElementsByClassName('logout')[0];
var userInfosvgdiv = document.getElementById('logouttooltip'); var userInfosvgdiv = document.getElementById('logouttooltip')!;
userInfosvgdiv.appendChild(logoutbutton); userInfosvgdiv.appendChild(logoutbutton);
fetch(`${location.origin}/seqta/student/load/message/people`, { } 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', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, },
body: JSON.stringify({ mode: 'student' }), body: JSON.stringify({ mode: 'student' }),
}) });
.then((result) => result.json())
.then((response) => { // Await the JSON parsing of the response
let students = response.payload; const responseData = await response.json();
var index = students.findIndex(function (person) { let students = responseData.payload;
// Process the students data
var index = students.findIndex(function (person: any) {
return ( return (
person.firstname == info.userDesc.split(' ')[0] && person.firstname == info.userDesc.split(' ')[0] &&
person.surname == info.userDesc.split(' ')[1] person.surname == info.userDesc.split(' ')[1]
); );
}); });
let houseelement = let houseelement = document.getElementsByClassName('userInfohouse')[0];
document.getElementsByClassName('userInfohouse')[0];
if (students[index]?.house) { if (students[index]?.house) {
houseelement.style.background = students[index].house_colour; houseelement.style.background = students[index].house_colour;
try { try {
let colorresult = GetThresholdOfColor( let colorresult = GetThresholdOfColor(students[index]?.house_colour);
students[index]?.house_colour,
);
if (colorresult && colorresult > 300) { houseelement.style.color = colorresult && colorresult > 300 ? 'black' : 'white';
houseelement.style.color = 'black'; houseelement.innerText = students[index].year + students[index].house;
} else if (colorresult < 300) {
houseelement.style.color = 'white';
} else {
houseelement.style.color = 'black';
}
houseelement.innerText =
students[index].year + students[index].house;
} catch (error) { } catch (error) {
houseelement.innerText = students[index].house; houseelement.innerText = students[index].house;
} }
} else { } else {
houseelement.innerText = students[index].year; houseelement.innerText = students[index].year;
} }
});
}); } catch (error) {
console.error('Error fetching and processing student data:', error);
}
var NewsButtonStr = '<li class="item" data-key="news" id="newsbutton" data-path="/news" data-betterseqta="true"><label><svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M20 3H4C2.89 3 2 3.89 2 5V19C2 20.11 2.89 21 4 21H20C21.11 21 22 20.11 22 19V5C22 3.89 21.11 3 20 3M5 7H10V13H5V7M19 17H5V15H19V17M19 13H12V11H19V13M19 9H12V7H19V9Z" /></svg>News</label></li>'; var NewsButtonStr = '<li class="item" data-key="news" id="newsbutton" data-path="/news" data-betterseqta="true"><label><svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M20 3H4C2.89 3 2 3.89 2 5V19C2 20.11 2.89 21 4 21H20C21.11 21 22 20.11 22 19V5C22 3.89 21.11 3 20 3M5 7H10V13H5V7M19 17H5V15H19V17M19 13H12V11H19V13M19 9H12V7H19V9Z" /></svg>News</label></li>';
var NewsButton = stringToHTML(NewsButtonStr); var NewsButton = stringToHTML(NewsButtonStr);