mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
can somebody help out here
This commit is contained in:
+39
-37
@@ -242,19 +242,19 @@ function OpenWhatsNewPopup() {
|
|||||||
container.append(header);
|
container.append(header);
|
||||||
container.append(imagecont);
|
container.append(imagecont);
|
||||||
container.append(textcontainer);
|
container.append(textcontainer);
|
||||||
container.append(text);
|
container.append(text as ChildNode);
|
||||||
container.append(footer);
|
container.append(footer as ChildNode);
|
||||||
container.append(exitbutton);
|
container.append(exitbutton);
|
||||||
|
|
||||||
background.append(container);
|
background.append(container);
|
||||||
|
|
||||||
document.getElementById('container').append(background);
|
document.getElementById('container')!.append(background);
|
||||||
|
|
||||||
let bkelement = document.getElementById('whatsnewbk');
|
let bkelement = document.getElementById('whatsnewbk');
|
||||||
let popup = document.getElementsByClassName('whatsnewContainer')[0];
|
let popup = document.getElementsByClassName('whatsnewContainer')[0];
|
||||||
|
|
||||||
animate(
|
animate(
|
||||||
[popup, bkelement],
|
[popup, bkelement as HTMLElement],
|
||||||
{ scale: [0, 1], opacity: [0, 1] },
|
{ scale: [0, 1], opacity: [0, 1] },
|
||||||
{ easing: spring({ stiffness: 220, damping: 18 }) }
|
{ easing: spring({ stiffness: 220, damping: 18 }) }
|
||||||
);
|
);
|
||||||
@@ -271,7 +271,7 @@ function OpenWhatsNewPopup() {
|
|||||||
|
|
||||||
browser.storage.local.remove(['justupdated']);
|
browser.storage.local.remove(['justupdated']);
|
||||||
|
|
||||||
bkelement.addEventListener('click', function (event) {
|
bkelement!.addEventListener('click', function (event) {
|
||||||
// Check if the click event originated from the element itself and not any of its children
|
// Check if the click event originated from the element itself and not any of its children
|
||||||
if (event.target === bkelement) {
|
if (event.target === bkelement) {
|
||||||
DeleteWhatsNew();
|
DeleteWhatsNew();
|
||||||
@@ -279,7 +279,7 @@ function OpenWhatsNewPopup() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var closeelement = document.getElementById('whatsnewclosebutton');
|
var closeelement = document.getElementById('whatsnewclosebutton');
|
||||||
closeelement.addEventListener('click', function () {
|
closeelement!.addEventListener('click', function () {
|
||||||
DeleteWhatsNew();
|
DeleteWhatsNew();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -287,16 +287,16 @@ function OpenWhatsNewPopup() {
|
|||||||
async function finishLoad() {
|
async function finishLoad() {
|
||||||
try {
|
try {
|
||||||
var loadingbk = document.getElementById('loading');
|
var loadingbk = document.getElementById('loading');
|
||||||
loadingbk.style.opacity = '0';
|
loadingbk!.style.opacity = '0';
|
||||||
await delay(501);
|
await delay(501);
|
||||||
loadingbk.remove();
|
loadingbk!.remove();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const result = browser.storage.local.get(['justupdated']);
|
const result = browser.storage.local.get(['justupdated']);
|
||||||
function open (result) {
|
function open (result: any) {
|
||||||
if (result.justupdated && !document.getElementById('whatsnewbk')) {
|
if (result.justupdated && !document.getElementById('whatsnewbk')) {
|
||||||
OpenWhatsNewPopup();
|
OpenWhatsNewPopup();
|
||||||
}
|
}
|
||||||
@@ -309,11 +309,11 @@ async function DeleteWhatsNew() {
|
|||||||
const popup = document.getElementsByClassName('whatsnewContainer')[0];
|
const popup = document.getElementsByClassName('whatsnewContainer')[0];
|
||||||
|
|
||||||
animate(
|
animate(
|
||||||
[popup, bkelement],
|
[popup, bkelement!],
|
||||||
{ opacity: [1, 0], scale: [1, 0] },
|
{ opacity: [1, 0], scale: [1, 0] },
|
||||||
{ easing: [.22, .03, .26, 1] }
|
{ easing: [.22, .03, .26, 1] }
|
||||||
).finished.then(() => {
|
).finished.then(() => {
|
||||||
bkelement.remove();
|
bkelement!.remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,17 +328,17 @@ export function CreateBackground() {
|
|||||||
var bk = document.createElement('div');
|
var bk = document.createElement('div');
|
||||||
bk.classList.add('bg');
|
bk.classList.add('bg');
|
||||||
|
|
||||||
bklocation.insertBefore(bk, menu);
|
bklocation!.insertBefore(bk, menu);
|
||||||
|
|
||||||
var bk2 = document.createElement('div');
|
var bk2 = document.createElement('div');
|
||||||
bk2.classList.add('bg');
|
bk2.classList.add('bg');
|
||||||
bk2.classList.add('bg2');
|
bk2.classList.add('bg2');
|
||||||
bklocation.insertBefore(bk2, menu);
|
bklocation!.insertBefore(bk2, menu);
|
||||||
|
|
||||||
var bk3 = document.createElement('div');
|
var bk3 = document.createElement('div');
|
||||||
bk3.classList.add('bg');
|
bk3.classList.add('bg');
|
||||||
bk3.classList.add('bg3');
|
bk3.classList.add('bg3');
|
||||||
bklocation.insertBefore(bk3, menu);
|
bklocation!.insertBefore(bk3, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RemoveBackground() {
|
export function RemoveBackground() {
|
||||||
@@ -353,7 +353,7 @@ export function RemoveBackground() {
|
|||||||
console.log('it deleted???')
|
console.log('it deleted???')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function waitForElm(selector) {
|
export function waitForElm(selector: any) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (document.querySelector(selector)) {
|
if (document.querySelector(selector)) {
|
||||||
return resolve(document.querySelector(selector));
|
return resolve(document.querySelector(selector));
|
||||||
@@ -373,7 +373,7 @@ export function waitForElm(selector) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function RunColourCheck(element) {
|
async function RunColourCheck(element: any) {
|
||||||
if (
|
if (
|
||||||
typeof element.contentDocument.documentElement.childNodes[1] == 'undefined'
|
typeof element.contentDocument.documentElement.childNodes[1] == 'undefined'
|
||||||
) {
|
) {
|
||||||
@@ -383,7 +383,7 @@ async function RunColourCheck(element) {
|
|||||||
element.contentDocument.documentElement.childNodes[1].style.color = 'white';
|
element.contentDocument.documentElement.childNodes[1].style.color = 'white';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function GetCSSElement (file) {
|
export function GetCSSElement (file: string) {
|
||||||
const cssFile = browser.runtime.getURL(file)
|
const cssFile = browser.runtime.getURL(file)
|
||||||
const fileref = document.createElement('link')
|
const fileref = document.createElement('link')
|
||||||
fileref.setAttribute('rel', 'stylesheet')
|
fileref.setAttribute('rel', 'stylesheet')
|
||||||
@@ -399,11 +399,12 @@ function removeThemeTagsFromNotices () {
|
|||||||
// Iterates through the array, applying the iFrame css
|
// Iterates through the array, applying the iFrame css
|
||||||
for (const item of userHTMLArray) {
|
for (const item of userHTMLArray) {
|
||||||
// Grabs the HTML of the body tag
|
// Grabs the HTML of the body tag
|
||||||
const body = item.contentWindow.document.querySelectorAll('body')[0]
|
const item1 = item as HTMLIFrameElement
|
||||||
|
const body = item1.contentWindow!.document.querySelectorAll('body')[0]
|
||||||
if (body) {
|
if (body) {
|
||||||
// Replaces the theme tag with nothing
|
// Replaces the theme tag with nothing
|
||||||
const bodyText = body.innerHTML
|
const bodyText = body.innerHTML
|
||||||
body.innerhtml = bodyText.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' ')
|
body.innerHTML = bodyText.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1410,7 +1411,7 @@ async function AddBetterSEQTAElements(toggle) {
|
|||||||
|
|
||||||
let tooltipstring;
|
let tooltipstring;
|
||||||
|
|
||||||
function GetLightDarkModeString(darkmodetoggle) {
|
function GetLightDarkModeString(darkmodetoggle: boolean) {
|
||||||
if (darkmodetoggle) {
|
if (darkmodetoggle) {
|
||||||
tooltipstring = 'Switch to light theme';
|
tooltipstring = 'Switch to light theme';
|
||||||
} else {
|
} else {
|
||||||
@@ -1419,7 +1420,7 @@ function GetLightDarkModeString(darkmodetoggle) {
|
|||||||
return tooltipstring;
|
return tooltipstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckCurrentLesson(lesson, num) {
|
function CheckCurrentLesson(lesson: any, num: number) {
|
||||||
var startTime = lesson.from;
|
var startTime = lesson.from;
|
||||||
var endTime = lesson.until;
|
var endTime = lesson.until;
|
||||||
// Gets current time
|
// Gets current time
|
||||||
@@ -1429,13 +1430,13 @@ function CheckCurrentLesson(lesson, num) {
|
|||||||
let startDate = new Date(currentDate.getTime());
|
let startDate = new Date(currentDate.getTime());
|
||||||
startDate.setHours(startTime.split(':')[0]);
|
startDate.setHours(startTime.split(':')[0]);
|
||||||
startDate.setMinutes(startTime.split(':')[1]);
|
startDate.setMinutes(startTime.split(':')[1]);
|
||||||
startDate.setSeconds('00');
|
startDate.setSeconds(parseInt('00'));
|
||||||
|
|
||||||
// Takes end time of current lesson and makes it into a Date function for comparison
|
// Takes end time of current lesson and makes it into a Date function for comparison
|
||||||
let endDate = new Date(currentDate.getTime());
|
let endDate = new Date(currentDate.getTime());
|
||||||
endDate.setHours(endTime.split(':')[0]);
|
endDate.setHours(endTime.split(':')[0]);
|
||||||
endDate.setMinutes(endTime.split(':')[1]);
|
endDate.setMinutes(endTime.split(':')[1]);
|
||||||
endDate.setSeconds('00');
|
endDate.setSeconds(parseInt('00'));
|
||||||
|
|
||||||
// Gets the difference between the start time and current time
|
// Gets the difference between the start time and current time
|
||||||
var difference = startDate.getTime() - currentDate.getTime();
|
var difference = startDate.getTime() - currentDate.getTime();
|
||||||
@@ -1518,7 +1519,7 @@ function CheckCurrentLesson(lesson, num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetThresholdOfColor(color) {
|
export function GetThresholdOfColor(color: any) {
|
||||||
// Case-insensitive regular expression for matching RGBA colors
|
// Case-insensitive regular expression for matching RGBA colors
|
||||||
const rgbaRegex = /rgba?\(([^)]+)\)/gi;
|
const rgbaRegex = /rgba?\(([^)]+)\)/gi;
|
||||||
|
|
||||||
@@ -1534,7 +1535,7 @@ export function GetThresholdOfColor(color) {
|
|||||||
const [r, g, b] = rgbaString.split(',').map(str => str.trim());
|
const [r, g, b] = rgbaString.split(',').map(str => str.trim());
|
||||||
|
|
||||||
// Compute the threshold using your existing algorithm
|
// Compute the threshold using your existing algorithm
|
||||||
const threshold = Math.sqrt(r ** 2 + g ** 2 + b ** 2);
|
const threshold = Math.sqrt(parseInt(r) ** 2 + parseInt(g) ** 2 + parseInt(b) ** 2);
|
||||||
|
|
||||||
// Store the computed threshold
|
// Store the computed threshold
|
||||||
gradientThresholds.push(threshold);
|
gradientThresholds.push(threshold);
|
||||||
@@ -1552,7 +1553,7 @@ export function GetThresholdOfColor(color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckCurrentLessonAll(lessons) {
|
function CheckCurrentLessonAll(lessons: any) {
|
||||||
// Checks each lesson and sets an interval to run every 60 seconds to continue updating
|
// Checks each lesson and sets an interval to run every 60 seconds to continue updating
|
||||||
LessonInterval = setInterval(
|
LessonInterval = setInterval(
|
||||||
function () {
|
function () {
|
||||||
@@ -1565,13 +1566,13 @@ function CheckCurrentLessonAll(lessons) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to build the assessment URL
|
// Helper function to build the assessment URL
|
||||||
function buildAssessmentURL(programmeID, metaID, itemID = '') {
|
function buildAssessmentURL(programmeID: any, metaID: any, itemID = '') {
|
||||||
const base = '../#?page=/assessments/';
|
const base = '../#?page=/assessments/';
|
||||||
return itemID ? `${base}${programmeID}:${metaID}&item=${itemID}` : `${base}${programmeID}:${metaID}`;
|
return itemID ? `${base}${programmeID}:${metaID}&item=${itemID}` : `${base}${programmeID}:${metaID}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to create a lesson div element from a lesson object
|
// Function to create a lesson div element from a lesson object
|
||||||
function makeLessonDiv(lesson, num) {
|
function makeLessonDiv(lesson: any, num: number) {
|
||||||
if (!lesson) throw new Error('No lesson provided.');
|
if (!lesson) throw new Error('No lesson provided.');
|
||||||
|
|
||||||
const { code, colour, description, staff, room, from, until, attendanceTitle, programmeID, metaID, assessments } = lesson;
|
const { code, colour, description, staff, room, from, until, attendanceTitle, programmeID, metaID, assessments } = lesson;
|
||||||
@@ -1596,7 +1597,7 @@ function makeLessonDiv(lesson, num) {
|
|||||||
|
|
||||||
// Add assessments if they exist
|
// Add assessments if they exist
|
||||||
if (assessments && assessments.length > 0) {
|
if (assessments && assessments.length > 0) {
|
||||||
const assessmentString = assessments.map(element =>
|
const assessmentString = assessments.map((element: any) =>
|
||||||
`<p onclick="document.querySelector('#menu ul').classList.add('noscroll'); location.href = '${buildAssessmentURL(programmeID, metaID, element.id)}';">${element.title}</p>`
|
`<p onclick="document.querySelector('#menu ul').classList.add('noscroll'); location.href = '${buildAssessmentURL(programmeID, metaID, element.id)}';">${element.title}</p>`
|
||||||
).join('');
|
).join('');
|
||||||
|
|
||||||
@@ -1615,7 +1616,7 @@ function makeLessonDiv(lesson, num) {
|
|||||||
return stringToHTML(lessonString);
|
return stringToHTML(lessonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckUnmarkedAttendance(lessonattendance) {
|
function CheckUnmarkedAttendance(lessonattendance: any) {
|
||||||
if (lessonattendance) {
|
if (lessonattendance) {
|
||||||
var lesson = lessonattendance.label;
|
var lesson = lessonattendance.label;
|
||||||
} else {
|
} else {
|
||||||
@@ -1624,7 +1625,7 @@ function CheckUnmarkedAttendance(lessonattendance) {
|
|||||||
return lesson;
|
return lesson;
|
||||||
}
|
}
|
||||||
|
|
||||||
function callHomeTimetable(date, change) {
|
function callHomeTimetable(date: Date, change: any) {
|
||||||
// Creates a HTTP Post Request to the SEQTA page for the students timetable
|
// Creates a HTTP Post Request to the SEQTA page for the students timetable
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('POST', `${location.origin}/seqta/student/load/timetable?`, true);
|
xhr.open('POST', `${location.origin}/seqta/student/load/timetable?`, true);
|
||||||
@@ -1635,11 +1636,11 @@ function callHomeTimetable(date, change) {
|
|||||||
// Once the response is ready
|
// Once the response is ready
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
var serverResponse = JSON.parse(xhr.response);
|
var serverResponse = JSON.parse(xhr.response);
|
||||||
let lessonArray = [];
|
let lessonArray: Array<any> = [];
|
||||||
var DayContainer = document.getElementById('day-container');
|
var DayContainer = document.getElementById('day-container');
|
||||||
// If items in response:
|
// If items in response:
|
||||||
if (serverResponse.payload.items.length > 0) {
|
if (serverResponse.payload.items.length > 0) {
|
||||||
if (!DayContainer.innerText || change) {
|
if (!DayContainer!.innerText || change) {
|
||||||
for (let i = 0; i < serverResponse.payload.items.length; i++) {
|
for (let i = 0; i < serverResponse.payload.items.length; i++) {
|
||||||
lessonArray.push(serverResponse.payload.items[i]);
|
lessonArray.push(serverResponse.payload.items[i]);
|
||||||
}
|
}
|
||||||
@@ -1654,7 +1655,7 @@ function callHomeTimetable(date, change) {
|
|||||||
let subjectname = `timetable.subject.colour.${lessonArray[i].code}`;
|
let subjectname = `timetable.subject.colour.${lessonArray[i].code}`;
|
||||||
|
|
||||||
let subject = subjects.find(
|
let subject = subjects.find(
|
||||||
(element) => element.name === subjectname,
|
(element: any) => element.name === subjectname,
|
||||||
);
|
);
|
||||||
if (!subject) {
|
if (!subject) {
|
||||||
lessonArray[i].colour = '--item-colour: #8e8e8e;';
|
lessonArray[i].colour = '--item-colour: #8e8e8e;';
|
||||||
@@ -1676,15 +1677,16 @@ function callHomeTimetable(date, change) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// If on home page, apply each lesson to HTML with information in each div
|
// If on home page, apply each lesson to HTML with information in each div
|
||||||
DayContainer.innerText = '';
|
DayContainer!.innerText = '';
|
||||||
for (let i = 0; i < lessonArray.length; i++) {
|
for (let i = 0; i < lessonArray.length; i++) {
|
||||||
var div = makeLessonDiv(lessonArray[i], i + 1);
|
var div = makeLessonDiv(lessonArray[i], i + 1);
|
||||||
// Append each of the lessons into the day-container
|
// Append each of the lessons into the day-container
|
||||||
if (lessonArray[i].invert) {
|
if (lessonArray[i].invert) {
|
||||||
div.firstChild.classList.add('day-inverted');
|
const div1 = div.firstChild! as HTMLElement
|
||||||
|
div1.classList.add('day-inverted');
|
||||||
}
|
}
|
||||||
|
|
||||||
DayContainer.append(div.firstChild);
|
DayContainer!.append(div.firstChild as HTMLElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|||||||
Reference in New Issue
Block a user