clean up dependencies

This commit is contained in:
SethBurkart123
2023-12-18 16:21:26 +11:00
parent 7342bcd0e8
commit 7247f426cd
2 changed files with 337 additions and 349 deletions
+335 -341
View File
@@ -1,32 +1,27 @@
import * as Sentry from "@sentry/browser"; import * as Sentry from "@sentry/browser";
import browser from 'webextension-polyfill';
import { animate, spring, stagger } from 'motion'; import { animate, spring, stagger } from 'motion';
import Sortable from 'sortablejs';
import Color from 'color';
import MenuitemSVGKey from './seqta/content/MenuItemSVGKey.json';
import ShortcutLinks from './seqta/content/links.json';
import { appendBackgroundToUI } from './seqta/ui/ImageBackgrounds';
import loading, { AppendLoadingSymbol } from './seqta/ui/Loading'; import loading, { AppendLoadingSymbol } from './seqta/ui/Loading';
import Color from 'color';
import MenuitemSVGKey from './seqta/content/MenuItemSVGKey.json';
import { MessageHandler } from './seqta/utils/MessageListener'; import { MessageHandler } from './seqta/utils/MessageListener';
import { updateAllColors } from './seqta/ui/colors/Manager';
import StorageListener from './seqta/utils/StorageListener';
import { updateBgDurations } from './seqta/ui/Animation';
import { enableCurrentTheme } from './seqta/ui/Themes';
import stringToHTML from './seqta/utils/stringToHTML';
import { response } from './seqta/utils/GetPrefs';
import { SettingsState } from "./types/storage"; import { SettingsState } from "./types/storage";
import { onError } from './seqta/utils/onError'; import ShortcutLinks from './seqta/content/links.json';
import { delay } from "./seqta/utils/delay"; import Sortable from 'sortablejs';
import StorageListener from './seqta/utils/StorageListener';
import iframeCSS from "./css/iframe.scss?inline"; import { appendBackgroundToUI } from './seqta/ui/ImageBackgrounds';
// Icons // Icons
import assessmentsicon from './seqta/icons/assessmentsIcon'; import assessmentsicon from './seqta/icons/assessmentsIcon';
import browser from 'webextension-polyfill';
import coursesicon from './seqta/icons/coursesIcon'; import coursesicon from './seqta/icons/coursesIcon';
import { delay } from "./seqta/utils/delay";
import { enableCurrentTheme } from './seqta/ui/Themes';
import iframeCSS from "./css/iframe.scss?inline";
import { onError } from './seqta/utils/onError';
import stringToHTML from './seqta/utils/stringToHTML';
import { updateAllColors } from './seqta/ui/colors/Manager';
import { updateBgDurations } from './seqta/ui/Animation';
browser.storage.local.get([ "telemetry" ]).then((telemetry) => { browser.storage.local.get([ "telemetry" ]).then((telemetry) => {
if (telemetry.telemetry === true) { if (telemetry.telemetry === true) {
@@ -726,7 +721,6 @@ function main(storedSetting: SettingsState) {
} }
updateAllColors(storedSetting); updateAllColors(storedSetting);
InjectStyles();
loading(); loading();
InjectCustomIcons(); InjectCustomIcons();
HideMenuItems(); HideMenuItems();
@@ -740,13 +734,6 @@ function main(storedSetting: SettingsState) {
} }
} }
function InjectStyles() {
import('./css/injected.scss');
const inject = GetCSSElement('css/injected.css');
document.head.appendChild(inject);
document.getElementsByTagName('html')[0].appendChild(inject);
}
function InjectCustomIcons() { function InjectCustomIcons() {
const fontURL = browser.runtime.getURL('fonts/IconFamily.woff'); const fontURL = browser.runtime.getURL('fonts/IconFamily.woff');
@@ -2183,85 +2170,77 @@ function AddCustomShortcutsToPage() {
result.then(open, onError) result.then(open, onError)
} }
function SendHomePage() { async function SendHomePage() {
setTimeout(function () { // Sends the html data for the home page
// Sends the html data for the home page console.log('[BetterSEQTA] Started Loading Home Page');
console.log('[BetterSEQTA] Started Loading Home Page'); document.title = 'Home ― SEQTA Learn';
document.title = 'Home ― SEQTA Learn'; var element = document.querySelector('[data-key=home]');
var element = document.querySelector('[data-key=home]');
// Apply the active class to indicate clicked on home button // Apply the active class to indicate clicked on home button
element!.classList.add('active'); element!.classList.add('active');
// Remove all current elements in the main div to add new elements // Remove all current elements in the main div to add new elements
var main = document.getElementById('main'); var main = document.getElementById('main');
main!.innerHTML = ''; main!.innerHTML = '';
const titlediv = document.getElementById('title')!.firstChild; const titlediv = document.getElementById('title')!.firstChild;
((titlediv!) as HTMLElement).innerText = 'Home'; ((titlediv!) as HTMLElement).innerText = 'Home';
(document.querySelector('link[rel*="icon"]')! as HTMLLinkElement).href = (document.querySelector('link[rel*="icon"]')! as HTMLLinkElement).href =
browser.runtime.getURL('icons/icon-48.png'); browser.runtime.getURL('icons/icon-48.png');
currentSelectedDate = new Date(); currentSelectedDate = new Date();
// Creates the root of the home page added to the main div // Creates the root of the home page added to the main div
var html = stringToHTML('<div class="home-root"><div class="home-container" id="home-container"></div></div>'); var html = stringToHTML('<div class="home-root"><div class="home-container" id="home-container"></div></div>');
// Appends the html file to main div // Appends the html file to main div
// Note : firstChild of html is done due to needing to grab the body from the stringToHTML function // Note : firstChild of html is done due to needing to grab the body from the stringToHTML function
main!.append(html.firstChild!); main!.append(html.firstChild!);
// Gets the current date // Gets the current date
const date = new Date();
// Formats the current date used send a request for timetable and notices later
var TodayFormatted =
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() < 10 ? '0' : '') + date.getDate();
// Replaces actual date with a selected date. Used for testing.
// TodayFormatted = "2020-08-31";
// Creates the shortcut container into the home container
var ShortcutStr = '<div class="shortcut-container border"><div class="shortcuts border" id="shortcuts"></div></div>';
var Shortcut = stringToHTML(ShortcutStr);
// Appends the shortcut container into the home container
document.getElementById('home-container')!.append(Shortcut.firstChild!);
// Creates the container div for the timetable portion of the home page
var TimetableStr = '<div class="timetable-container border"><div class="home-subtitle"><h2 id="home-lesson-subtitle">Today\'s Lessons</h2><div class="timetable-arrows"><svg width="24" height="24" viewBox="0 0 24 24" style="transform: scale(-1,1)" id="home-timetable-back"><g style="fill: currentcolor;"><path d="M8.578 16.359l4.594-4.594-4.594-4.594 1.406-1.406 6 6-6 6z"></path></g></svg><svg width="24" height="24" viewBox="0 0 24 24" id="home-timetable-forward"><g style="fill: currentcolor;"><path d="M8.578 16.359l4.594-4.594-4.594-4.594 1.406-1.406 6 6-6 6z"></path></g></svg></div></div><div class="day-container" id="day-container"></div></div>';
var Timetable = stringToHTML(TimetableStr);
// Appends the timetable container into the home container
document.getElementById('home-container')!.append(Timetable.firstChild!);
callHomeTimetable(TodayFormatted, true)
var timetablearrowback = document.getElementById('home-timetable-back');
var timetablearrowforward = document.getElementById(
'home-timetable-forward',
);
function SetTimetableSubtitle() {
var homelessonsubtitle = document.getElementById('home-lesson-subtitle');
const date = new Date(); const date = new Date();
if (
// Formats the current date used send a request for timetable and notices later date.getFullYear() == currentSelectedDate.getFullYear() &&
var TodayFormatted = date.getMonth() == currentSelectedDate.getMonth()
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() < 10 ? '0' : '') + date.getDate(); ) {
if (date.getDate() == currentSelectedDate.getDate()) {
// Replaces actual date with a selected date. Used for testing. // Change text to Today's Lessons
// TodayFormatted = "2020-08-31"; homelessonsubtitle!.innerText = 'Today\'s Lessons';
} else if (date.getDate() - 1 == currentSelectedDate.getDate()) {
// Creates the shortcut container into the home container // Change text to Yesterday's Lessons
var ShortcutStr = '<div class="shortcut-container border"><div class="shortcuts border" id="shortcuts"></div></div>'; homelessonsubtitle!.innerText = 'Yesterday\'s Lessons';
var Shortcut = stringToHTML(ShortcutStr); } else if (date.getDate() + 1 == currentSelectedDate.getDate()) {
// Appends the shortcut container into the home container // Change text to Tomorrow's Lessons
document.getElementById('home-container')!.append(Shortcut.firstChild!); homelessonsubtitle!.innerText = 'Tomorrow\'s Lessons';
// Creates the container div for the timetable portion of the home page
var TimetableStr = '<div class="timetable-container border"><div class="home-subtitle"><h2 id="home-lesson-subtitle">Today\'s Lessons</h2><div class="timetable-arrows"><svg width="24" height="24" viewBox="0 0 24 24" style="transform: scale(-1,1)" id="home-timetable-back"><g style="fill: currentcolor;"><path d="M8.578 16.359l4.594-4.594-4.594-4.594 1.406-1.406 6 6-6 6z"></path></g></svg><svg width="24" height="24" viewBox="0 0 24 24" id="home-timetable-forward"><g style="fill: currentcolor;"><path d="M8.578 16.359l4.594-4.594-4.594-4.594 1.406-1.406 6 6-6 6z"></path></g></svg></div></div><div class="day-container" id="day-container"></div></div>';
var Timetable = stringToHTML(TimetableStr);
// Appends the timetable container into the home container
document.getElementById('home-container')!.append(Timetable.firstChild!);
callHomeTimetable(TodayFormatted, true)
var timetablearrowback = document.getElementById('home-timetable-back');
var timetablearrowforward = document.getElementById(
'home-timetable-forward',
);
function SetTimetableSubtitle() {
var homelessonsubtitle = document.getElementById('home-lesson-subtitle');
const date = new Date();
if (
date.getFullYear() == currentSelectedDate.getFullYear() &&
date.getMonth() == currentSelectedDate.getMonth()
) {
if (date.getDate() == currentSelectedDate.getDate()) {
// Change text to Today's Lessons
homelessonsubtitle!.innerText = 'Today\'s Lessons';
} else if (date.getDate() - 1 == currentSelectedDate.getDate()) {
// Change text to Yesterday's Lessons
homelessonsubtitle!.innerText = 'Yesterday\'s Lessons';
} else if (date.getDate() + 1 == currentSelectedDate.getDate()) {
// Change text to Tomorrow's Lessons
homelessonsubtitle!.innerText = 'Tomorrow\'s Lessons';
} else {
// Change text to date of the day
homelessonsubtitle!.innerText = `${currentSelectedDate.toLocaleString(
'en-us',
{ weekday: 'short' },
)} ${currentSelectedDate.toLocaleDateString('en-au')}`;
}
} else { } else {
// Change text to date of the day // Change text to date of the day
homelessonsubtitle!.innerText = `${currentSelectedDate.toLocaleString( homelessonsubtitle!.innerText = `${currentSelectedDate.toLocaleString(
@@ -2269,99 +2248,192 @@ function SendHomePage() {
{ weekday: 'short' }, { weekday: 'short' },
)} ${currentSelectedDate.toLocaleDateString('en-au')}`; )} ${currentSelectedDate.toLocaleDateString('en-au')}`;
} }
} else {
// Change text to date of the day
homelessonsubtitle!.innerText = `${currentSelectedDate.toLocaleString(
'en-us',
{ weekday: 'short' },
)} ${currentSelectedDate.toLocaleDateString('en-au')}`;
} }
}
function changeTimetable(value: any) { function changeTimetable(value: any) {
currentSelectedDate.setDate(currentSelectedDate.getDate() + value); currentSelectedDate.setDate(currentSelectedDate.getDate() + value);
let FormattedDate = let FormattedDate =
currentSelectedDate.getFullYear() + currentSelectedDate.getFullYear() +
'-' + '-' +
(currentSelectedDate.getMonth() + 1) + (currentSelectedDate.getMonth() + 1) +
'-' + '-' +
currentSelectedDate.getDate(); currentSelectedDate.getDate();
callHomeTimetable(FormattedDate, true); callHomeTimetable(FormattedDate, true);
SetTimetableSubtitle(); SetTimetableSubtitle();
}
timetablearrowback!.addEventListener('click', function () {
changeTimetable(-1);
});
timetablearrowforward!.addEventListener('click', function () {
changeTimetable(1);
});
// Adds the shortcuts to the shortcut container
const result = browser.storage.local.get(['shortcuts'])
function open (result: any) {
const shortcuts = Object.values(result)[0];
addShortcuts(shortcuts);
}
result.then(open, onError)
// Creates the upcoming container and appends to the home container
var upcomingcontainer = document.createElement('div');
upcomingcontainer.classList.add('upcoming-container');
upcomingcontainer.classList.add('border');
let upcomingtitlediv = CreateElement('div', 'upcoming-title');
let upcomingtitle = document.createElement('h2');
upcomingtitle.classList.add('home-subtitle');
upcomingtitle.innerText = 'Upcoming Assessments';
upcomingtitlediv.append(upcomingtitle);
let upcomingfilterdiv = CreateElement(
'div',
'upcoming-filters',
'upcoming-filters',
);
upcomingtitlediv.append(upcomingfilterdiv);
upcomingcontainer.append(upcomingtitlediv);
let upcomingitems = document.createElement('div');
upcomingitems.id = 'upcoming-items';
upcomingitems.classList.add('upcoming-items');
upcomingcontainer.append(upcomingitems);
document.getElementById('home-container')!.append(upcomingcontainer);
// Creates the notices container into the home container
const NoticesStr = String.raw`
<div class="notices-container border">
<div style="display: flex; justify-content: space-between">
<h2 class="home-subtitle">Notices</h2>
<input type="date" value=${TodayFormatted} />
</div>
<div class="notice-container" id="notice-container"></div>
</div>`
var Notices = stringToHTML(NoticesStr);
// Appends the shortcut container into the home container
document.getElementById('home-container')!.append(Notices.firstChild!);
animate(
'.home-container > div',
{ opacity: [0, 1], y: [10, 0] },
{
delay: stagger(0.2, { start: 0 }),
duration: 0.6,
easing: [.22, .03, .26, 1]
} }
);
timetablearrowback!.addEventListener('click', function () { callHomeTimetable(TodayFormatted);
changeTimetable(-1);
});
timetablearrowforward!.addEventListener('click', function () {
changeTimetable(1);
});
// Adds the shortcuts to the shortcut container const GetPrefs = await fetch(`${location.origin}/seqta/student/load/prefs?`, {
const result = browser.storage.local.get(['shortcuts']) method: 'POST',
function open (result: any) { headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ asArray: true, request: 'userPrefs' })
})
const shortcuts = Object.values(result)[0]; const response = await GetPrefs.json()
addShortcuts(shortcuts);
}
result.then(open, onError)
// Creates the upcoming container and appends to the home container const labelArray = response.payload[1].value.split(' ')
var upcomingcontainer = document.createElement('div');
upcomingcontainer.classList.add('upcoming-container');
upcomingcontainer.classList.add('border');
let upcomingtitlediv = CreateElement('div', 'upcoming-title'); const xhr2 = new XMLHttpRequest()
let upcomingtitle = document.createElement('h2'); xhr2.open(
upcomingtitle.classList.add('home-subtitle'); 'POST',
upcomingtitle.innerText = 'Upcoming Assessments'; `${location.origin}/seqta/student/load/notices?`,
upcomingtitlediv.append(upcomingtitle); true
)
xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8')
let upcomingfilterdiv = CreateElement( xhr2.onreadystatechange = function () {
'div', if (xhr2.readyState === 4) {
'upcoming-filters', const NoticesPayload = JSON.parse(xhr2.response)
'upcoming-filters', const NoticeContainer = document.getElementById('notice-container')
); if (NoticesPayload.payload.length === 0) {
upcomingtitlediv.append(upcomingfilterdiv); if (!NoticeContainer!.innerText) {
// If no notices: display no notices
const dummyNotice = document.createElement('div')
dummyNotice.textContent = 'No notices for today.'
dummyNotice.classList.add('dummynotice')
NoticeContainer!.append(dummyNotice)
}
} else {
if (!NoticeContainer!.innerText) {
// For each element in the response json:
const result = browser.storage.local.get(['DarkMode'])
function noticeInfoDiv (result: any) {
for (let i = 0; i < NoticesPayload.payload.length; i++) {
if (labelArray.includes(JSON.stringify(NoticesPayload.payload[i].label))) {
// Create a div, and place information from json response
const NewNotice = document.createElement('div')
NewNotice.classList.add('notice')
const title = stringToHTML(
'<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>'
)
NewNotice.append(title.firstChild!)
upcomingcontainer.append(upcomingtitlediv); if (NoticesPayload.payload[i].label_title !== undefined) {
const label = stringToHTML(
'<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>'
)
NewNotice.append(label.firstChild!)
}
let upcomingitems = document.createElement('div'); const staff = stringToHTML(
upcomingitems.id = 'upcoming-items'; '<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>'
upcomingitems.classList.add('upcoming-items'); )
NewNotice.append(staff.firstChild!)
// Converts the string into HTML
const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true)
for (let i = 0; i < content.childNodes.length; i++) {
NewNotice.append(content.childNodes[i])
}
// Gets the colour for the top section of each notice
upcomingcontainer.append(upcomingitems); let colour = NoticesPayload.payload[i].colour
if (typeof (colour) === 'string') {
const rgb = GetThresholdOfColor(colour)
const DarkModeResult = result.DarkMode
if (rgb < 100 && DarkModeResult) {
colour = undefined
}
}
document.getElementById('home-container')!.append(upcomingcontainer); const colourbar = document.createElement('div')
colourbar.classList.add('colourbar')
// Creates the notices container into the home container colourbar.style.background = 'var(--colour)'
const NoticesStr = String.raw` NewNotice.style.cssText = `--colour: ${colour}`
<div class="notices-container border"> // Appends the colour bar to the new notice
<div style="display: flex; justify-content: space-between"> NewNotice.append(colourbar)
<h2 class="home-subtitle">Notices</h2> // Appends the new notice into the notice container
<input type="date" value=${TodayFormatted} /> NoticeContainer!.append(NewNotice)
</div> }
<div class="notice-container" id="notice-container"></div> }
</div>` }
result.then(noticeInfoDiv, onError)
var Notices = stringToHTML(NoticesStr); }
// Appends the shortcut container into the home container
document.getElementById('home-container')!.append(Notices.firstChild!);
animate(
'.home-container > div',
{ opacity: [0, 1], y: [10, 0] },
{
delay: stagger(0.2, { start: 0 }),
duration: 0.6,
easing: [.22, .03, .26, 1]
} }
); }
}
callHomeTimetable(TodayFormatted); // Data sent as the POST request
const labelArray = response.payload[1].value.split(' ') const dateControl = document.querySelector('input[type="date"]') as HTMLInputElement
xhr2.send(JSON.stringify({ date: dateControl!.value }))
const xhr2 = new XMLHttpRequest() function onInputChange (e: any) {
xhr2.open( xhr2.open('POST', `${location.origin}/seqta/student/load/notices?`, true)
'POST',
`${location.origin}/seqta/student/load/notices?`,
true
)
xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8') xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8')
xhr2.send(JSON.stringify({ date: e.target.value }))
xhr2.onreadystatechange = function () { xhr2.onreadystatechange = function () {
if (xhr2.readyState === 4) { if (xhr2.readyState === 4) {
const NoticesPayload = JSON.parse(xhr2.response) const NoticesPayload = JSON.parse(xhr2.response)
@@ -2375,187 +2447,109 @@ function SendHomePage() {
NoticeContainer!.append(dummyNotice) NoticeContainer!.append(dummyNotice)
} }
} else { } else {
if (!NoticeContainer!.innerText) { document.querySelectorAll('.notice').forEach(e => e.remove())
// For each element in the response json: // For each element in the response json:
const result = browser.storage.local.get(['DarkMode']) const result = browser.storage.local.get(['DarkMode'])
function noticeInfoDiv (result: any) { function noticeInfoDiv (result: any) {
for (let i = 0; i < NoticesPayload.payload.length; i++) { for (let i = 0; i < NoticesPayload.payload.length; i++) {
if (labelArray.includes(JSON.stringify(NoticesPayload.payload[i].label))) {
// Create a div, and place information from json response if (labelArray.includes(JSON.stringify(NoticesPayload.payload[i].label))) {
const NewNotice = document.createElement('div') // Create a div, and place information from json response
NewNotice.classList.add('notice') const NewNotice = document.createElement('div')
const title = stringToHTML( NewNotice.classList.add('notice')
'<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>' const title = stringToHTML(
'<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>'
)
NewNotice.append(title.firstChild!)
if (NoticesPayload.payload[i].label_title !== undefined) {
const label = stringToHTML(
'<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>'
) )
NewNotice.append(title.firstChild!) NewNotice.append(label.firstChild!)
if (NoticesPayload.payload[i].label_title !== undefined) {
const label = stringToHTML(
'<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>'
)
NewNotice.append(label.firstChild!)
}
const staff = stringToHTML(
'<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>'
)
NewNotice.append(staff.firstChild!)
// Converts the string into HTML
const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true)
for (let i = 0; i < content.childNodes.length; i++) {
NewNotice.append(content.childNodes[i])
}
// Gets the colour for the top section of each notice
let colour = NoticesPayload.payload[i].colour
if (typeof (colour) === 'string') {
const rgb = GetThresholdOfColor(colour)
const DarkModeResult = result.DarkMode
if (rgb < 100 && DarkModeResult) {
colour = undefined
}
}
const colourbar = document.createElement('div')
colourbar.classList.add('colourbar')
colourbar.style.background = 'var(--colour)'
NewNotice.style.cssText = `--colour: ${colour}`
// Appends the colour bar to the new notice
NewNotice.append(colourbar)
// Appends the new notice into the notice container
NoticeContainer!.append(NewNotice)
} }
const staff = stringToHTML(
'<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>'
)
NewNotice.append(staff.firstChild!)
// Converts the string into HTML
const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true)
for (let i = 0; i < content.childNodes.length; i++) {
NewNotice.append(content.childNodes[i])
}
// Gets the colour for the top section of each notice
let colour = NoticesPayload.payload[i].colour
if (typeof (colour) === 'string') {
const rgb = GetThresholdOfColor(colour)
const DarkModeResult = result.DarkMode
if (rgb < 100 && DarkModeResult) {
colour = undefined
}
}
const colourbar = document.createElement('div')
colourbar.classList.add('colourbar')
colourbar.style.background = 'var(--colour)'
NewNotice.style.cssText = `--colour: ${colour}`
// Appends the colour bar to the new notice
NewNotice.append(colourbar)
// Appends the new notice into the notice container
NoticeContainer!.append(NewNotice)
} }
} }
result.then(noticeInfoDiv, onError)
} }
result.then(noticeInfoDiv, onError)
} }
} }
} }
// Data sent as the POST request }
const dateControl = document.querySelector('input[type="date"]') as HTMLInputElement dateControl.addEventListener('input', onInputChange)
xhr2.send(JSON.stringify({ date: dateControl!.value }))
function onInputChange (e: any) {
xhr2.open('POST', `${location.origin}/seqta/student/load/notices?`, true)
xhr2.setRequestHeader('Content-Type', 'application/json; charset=utf-8')
xhr2.send(JSON.stringify({ date: e.target.value }))
xhr2.onreadystatechange = function () {
if (xhr2.readyState === 4) {
const NoticesPayload = JSON.parse(xhr2.response)
const NoticeContainer = document.getElementById('notice-container')
if (NoticesPayload.payload.length === 0) {
if (!NoticeContainer!.innerText) {
// If no notices: display no notices
const dummyNotice = document.createElement('div')
dummyNotice.textContent = 'No notices for today.'
dummyNotice.classList.add('dummynotice')
NoticeContainer!.append(dummyNotice)
}
} else {
document.querySelectorAll('.notice').forEach(e => e.remove())
// For each element in the response json:
const result = browser.storage.local.get(['DarkMode'])
function noticeInfoDiv (result: any) {
for (let i = 0; i < NoticesPayload.payload.length; i++) {
if (labelArray.includes(JSON.stringify(NoticesPayload.payload[i].label))) { // Sends similar HTTP Post Request for the notices
// Create a div, and place information from json response const result1 = browser.storage.local.get()
const NewNotice = document.createElement('div') function open1 (result: any) {
NewNotice.classList.add('notice') if (result.notificationcollector) {
const title = stringToHTML( enableNotificationCollector();
'<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>' }
) }
NewNotice.append(title.firstChild!) result1.then(open1, onError)
let activeClassList: any;
if (NoticesPayload.payload[i].label_title !== undefined) { GetUpcomingAssessments().then((assessments) => {
const label = stringToHTML( GetActiveClasses().then((classes) => {
'<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>' // Gets all subjects for the student
) for (let i = 0; i < classes.length; i++) {
NewNotice.append(label.firstChild!) const element = classes[i];
} // eslint-disable-next-line
if (element.hasOwnProperty("active")) { // for some reason eslint gets mad, even though it works?
const staff = stringToHTML( // Finds the active class list with the current subjects
'<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>' activeClassList = classes[i];
)
NewNotice.append(staff.firstChild!)
// Converts the string into HTML
const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true)
for (let i = 0; i < content.childNodes.length; i++) {
NewNotice.append(content.childNodes[i])
}
// Gets the colour for the top section of each notice
let colour = NoticesPayload.payload[i].colour
if (typeof (colour) === 'string') {
const rgb = GetThresholdOfColor(colour)
const DarkModeResult = result.DarkMode
if (rgb < 100 && DarkModeResult) {
colour = undefined
}
}
const colourbar = document.createElement('div')
colourbar.classList.add('colourbar')
colourbar.style.background = 'var(--colour)'
NewNotice.style.cssText = `--colour: ${colour}`
// Appends the colour bar to the new notice
NewNotice.append(colourbar)
// Appends the new notice into the notice container
NoticeContainer!.append(NewNotice)
}
}
}
result.then(noticeInfoDiv, onError)
}
} }
} }
} let activeSubjects = activeClassList.subjects;
dateControl.addEventListener('input', onInputChange)
// Sends similar HTTP Post Request for the notices let activeSubjectCodes = [];
const result1 = browser.storage.local.get() // Gets the code for each of the subjects and puts them in an array
function open1 (result: any) { let element;
if (result.notificationcollector) { for (let i = 0; i < activeSubjects.length; i++) {
enableNotificationCollector(); element = activeSubjects[i];
activeSubjectCodes.push(element.code);
} }
}
result1.then(open1, onError) let CurrentAssessments = [];
let activeClassList: any; for (let i = 0; i < assessments.length; i++) {
GetUpcomingAssessments().then((assessments) => { element = assessments[i];
GetActiveClasses().then((classes) => { if (activeSubjectCodes.includes(element.code)) {
// Gets all subjects for the student CurrentAssessments.push(element);
for (let i = 0; i < classes.length; i++) {
const element = classes[i];
// eslint-disable-next-line
if (element.hasOwnProperty("active")) { // for some reason eslint gets mad, even though it works?
// Finds the active class list with the current subjects
activeClassList = classes[i];
}
} }
let activeSubjects = activeClassList.subjects; }
let activeSubjectCodes = []; CurrentAssessments.sort(comparedate);
// Gets the code for each of the subjects and puts them in an array
let element;
for (let i = 0; i < activeSubjects.length; i++) {
element = activeSubjects[i];
activeSubjectCodes.push(element.code);
}
let CurrentAssessments = []; CreateUpcomingSection(CurrentAssessments, activeSubjects);
for (let i = 0; i < assessments.length; i++) {
element = assessments[i];
if (activeSubjectCodes.includes(element.code)) {
CurrentAssessments.push(element);
}
}
CurrentAssessments.sort(comparedate);
CreateUpcomingSection(CurrentAssessments, activeSubjects);
});
}); });
}, 8); });
} }
export function addShortcuts(shortcuts: any) { export function addShortcuts(shortcuts: any) {
-6
View File
@@ -1,6 +0,0 @@
const GetPrefs = await fetch(`${location.origin}/seqta/student/load/prefs?`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ asArray: true, request: 'userPrefs' })
})
export const response = await GetPrefs.json()