LET'S FUCKING GOOO!!! (needs testing though)

This commit is contained in:
Crazypersonalph
2023-12-04 20:19:01 +08:00
parent 3fba6dd3be
commit aaca124ff0
+73 -75
View File
@@ -1649,7 +1649,7 @@ function CheckUnmarkedAttendance(lessonattendance: any) {
return lesson; return lesson;
} }
function callHomeTimetable(date: Date, change: any) { function callHomeTimetable(date: string, 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);
@@ -1985,7 +1985,7 @@ function CreateFilters(subjects: any) {
result.then(open, onError) result.then(open, onError)
} }
function CreateUpcomingSection(assessments: any) { function CreateUpcomingSection(assessments: any, activeSubjects: any) {
let upcomingitemcontainer = document.querySelector('#upcoming-items'); let upcomingitemcontainer = document.querySelector('#upcoming-items');
let overdueDates = []; let overdueDates = [];
let upcomingDates = {}; let upcomingDates = {};
@@ -2026,8 +2026,6 @@ function CreateUpcomingSection(assessments: any) {
GetThresholdOfColor(subject.value); // result (originally) result = GetThresholdOfColor GetThresholdOfColor(subject.value); // result (originally) result = GetThresholdOfColor
} }
} }
let activeSubjects: any = []; // TODO: IDK what is going on here, but it didn't exist
for (let i = 0; i < activeSubjects.length; i++) { for (let i = 0; i < activeSubjects.length; i++) {
const element = activeSubjects[i]; const element = activeSubjects[i];
let subjectname = `timetable.subject.colour.${element.code}`; let subjectname = `timetable.subject.colour.${element.code}`;
@@ -2205,18 +2203,18 @@ export function CreateCustomShortcutDiv(element: any) {
</svg> </svg>
`, `,
).firstChild; ).firstChild;
image.classList.add('shortcuticondiv'); (image as HTMLElement).classList.add('shortcuticondiv');
var text = document.createElement('p'); var text = document.createElement('p');
text.textContent = element.name; text.textContent = element.name;
shortcutdiv.append(image); shortcutdiv.append(image!);
shortcutdiv.append(text); shortcutdiv.append(text);
shortcut.append(shortcutdiv); shortcut.append(shortcutdiv);
document.getElementById('shortcuts').append(shortcut); document.getElementById('shortcuts')!.append(shortcut);
} }
export function RemoveShortcutDiv(elements) { export function RemoveShortcutDiv(elements: any) {
elements.forEach((element) => { elements.forEach((element: any) => {
const shortcuts = document.querySelectorAll('.shortcut'); const shortcuts = document.querySelectorAll('.shortcut');
shortcuts.forEach((shortcut) => { shortcuts.forEach((shortcut) => {
const anchorElement = shortcut.parentElement; // the <a> element is the parent const anchorElement = shortcut.parentElement; // the <a> element is the parent
@@ -2227,11 +2225,11 @@ export function RemoveShortcutDiv(elements) {
// Check href only if element.url exists // Check href only if element.url exists
if (element.url) { if (element.url) {
shouldRemove = shouldRemove && (anchorElement.getAttribute('href') === element.url); shouldRemove = shouldRemove && (anchorElement!.getAttribute('href') === element.url);
} }
if (shouldRemove) { if (shouldRemove) {
anchorElement.remove(); anchorElement!.remove();
} }
}); });
}); });
@@ -2239,11 +2237,11 @@ export function RemoveShortcutDiv(elements) {
function AddCustomShortcutsToPage() { function AddCustomShortcutsToPage() {
const result = browser.storage.local.get(['customshortcuts']) const result = browser.storage.local.get(['customshortcuts'])
function open (result) { function open (result: any) {
var customshortcuts = Object.values(result)[0]; var customshortcuts: any = Object.values(result)[0];
if (customshortcuts.length > 0) { if (customshortcuts.length > 0) {
document.getElementsByClassName('shortcut-container')[0].style.display = (document.getElementsByClassName('shortcut-container')[0] as HTMLElement).style.display =
'block'; 'block';
for (let i = 0; i < customshortcuts.length; i++) { for (let i = 0; i < customshortcuts.length; i++) {
const element = customshortcuts[i]; const element = customshortcuts[i];
@@ -2262,15 +2260,15 @@ function SendHomePage() {
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.innerText = 'Home'; ((titlediv!) as HTMLElement).innerText = 'Home';
document.querySelector('link[rel*="icon"]').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();
@@ -2280,7 +2278,7 @@ function SendHomePage() {
// 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(); const date = new Date();
@@ -2296,13 +2294,13 @@ function SendHomePage() {
var ShortcutStr = '<div class="shortcut-container border"><div class="shortcuts border" id="shortcuts"></div></div>'; var ShortcutStr = '<div class="shortcut-container border"><div class="shortcuts border" id="shortcuts"></div></div>';
var Shortcut = stringToHTML(ShortcutStr); var Shortcut = stringToHTML(ShortcutStr);
// Appends the shortcut container into the home container // Appends the shortcut container into the home container
document.getElementById('home-container').append(Shortcut.firstChild); document.getElementById('home-container')!.append(Shortcut.firstChild!);
// Creates the container div for the timetable portion of the home page // 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 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); var Timetable = stringToHTML(TimetableStr);
// Appends the timetable container into the home container // Appends the timetable container into the home container
document.getElementById('home-container').append(Timetable.firstChild); document.getElementById('home-container')!.append(Timetable.firstChild!);
var timetablearrowback = document.getElementById('home-timetable-back'); var timetablearrowback = document.getElementById('home-timetable-back');
var timetablearrowforward = document.getElementById( var timetablearrowforward = document.getElementById(
@@ -2313,35 +2311,35 @@ function SendHomePage() {
var homelessonsubtitle = document.getElementById('home-lesson-subtitle'); var homelessonsubtitle = document.getElementById('home-lesson-subtitle');
const date = new Date(); const date = new Date();
if ( if (
date.getYear() == currentSelectedDate.getYear() && date.getFullYear() == currentSelectedDate.getFullYear() &&
date.getMonth() == currentSelectedDate.getMonth() date.getMonth() == currentSelectedDate.getMonth()
) { ) {
if (date.getDate() == currentSelectedDate.getDate()) { if (date.getDate() == currentSelectedDate.getDate()) {
// Change text to Today's Lessons // Change text to Today's Lessons
homelessonsubtitle.innerText = 'Today\'s Lessons'; homelessonsubtitle!.innerText = 'Today\'s Lessons';
} else if (date.getDate() - 1 == currentSelectedDate.getDate()) { } else if (date.getDate() - 1 == currentSelectedDate.getDate()) {
// Change text to Yesterday's Lessons // Change text to Yesterday's Lessons
homelessonsubtitle.innerText = 'Yesterday\'s Lessons'; homelessonsubtitle!.innerText = 'Yesterday\'s Lessons';
} else if (date.getDate() + 1 == currentSelectedDate.getDate()) { } else if (date.getDate() + 1 == currentSelectedDate.getDate()) {
// Change text to Tomorrow's Lessons // Change text to Tomorrow's Lessons
homelessonsubtitle.innerText = 'Tomorrow\'s Lessons'; homelessonsubtitle!.innerText = 'Tomorrow\'s Lessons';
} else { } else {
// Change text to date of the day // Change text to date of the day
homelessonsubtitle.innerText = `${currentSelectedDate.toLocaleString( homelessonsubtitle!.innerText = `${currentSelectedDate.toLocaleString(
'en-us', 'en-us',
{ weekday: 'short' }, { weekday: 'short' },
)} ${currentSelectedDate.toLocaleDateString('en-au')}`; )} ${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(
'en-us', 'en-us',
{ weekday: 'short' }, { weekday: 'short' },
)} ${currentSelectedDate.toLocaleDateString('en-au')}`; )} ${currentSelectedDate.toLocaleDateString('en-au')}`;
} }
} }
function changeTimetable(value) { function changeTimetable(value: any) {
currentSelectedDate.setDate(currentSelectedDate.getDate() + value); currentSelectedDate.setDate(currentSelectedDate.getDate() + value);
let FormattedDate = let FormattedDate =
currentSelectedDate.getFullYear() + currentSelectedDate.getFullYear() +
@@ -2353,16 +2351,16 @@ function SendHomePage() {
SetTimetableSubtitle(); SetTimetableSubtitle();
} }
timetablearrowback.addEventListener('click', function () { timetablearrowback!.addEventListener('click', function () {
changeTimetable(-1); changeTimetable(-1);
}); });
timetablearrowforward.addEventListener('click', function () { timetablearrowforward!.addEventListener('click', function () {
changeTimetable(1); changeTimetable(1);
}); });
// Adds the shortcuts to the shortcut container // Adds the shortcuts to the shortcut container
const result = browser.storage.local.get(['shortcuts']) const result = browser.storage.local.get(['shortcuts'])
function open (result) { function open (result: any) {
const shortcuts = Object.values(result)[0]; const shortcuts = Object.values(result)[0];
addShortcuts(shortcuts); addShortcuts(shortcuts);
@@ -2395,7 +2393,7 @@ function SendHomePage() {
upcomingcontainer.append(upcomingitems); upcomingcontainer.append(upcomingitems);
document.getElementById('home-container').append(upcomingcontainer); document.getElementById('home-container')!.append(upcomingcontainer);
// Creates the notices container into the home container // Creates the notices container into the home container
const NoticesStr = String.raw` const NoticesStr = String.raw`
@@ -2409,7 +2407,7 @@ function SendHomePage() {
var Notices = stringToHTML(NoticesStr); var Notices = stringToHTML(NoticesStr);
// Appends the shortcut container into the home container // Appends the shortcut container into the home container
document.getElementById('home-container').append(Notices.firstChild); document.getElementById('home-container')!.append(Notices.firstChild!);
animate( animate(
'.home-container > div', '.home-container > div',
@@ -2437,18 +2435,18 @@ function SendHomePage() {
const NoticesPayload = JSON.parse(xhr2.response) const NoticesPayload = JSON.parse(xhr2.response)
const NoticeContainer = document.getElementById('notice-container') const NoticeContainer = document.getElementById('notice-container')
if (NoticesPayload.payload.length === 0) { if (NoticesPayload.payload.length === 0) {
if (!NoticeContainer.innerText) { if (!NoticeContainer!.innerText) {
// If no notices: display no notices // If no notices: display no notices
const dummyNotice = document.createElement('div') const dummyNotice = document.createElement('div')
dummyNotice.textContent = 'No notices for today.' dummyNotice.textContent = 'No notices for today.'
dummyNotice.classList.add('dummynotice') dummyNotice.classList.add('dummynotice')
NoticeContainer.append(dummyNotice) NoticeContainer!.append(dummyNotice)
} }
} else { } else {
if (!NoticeContainer.innerText) { if (!NoticeContainer!.innerText) {
// 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) { 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))) { if (labelArray.includes(JSON.stringify(NoticesPayload.payload[i].label))) {
// Create a div, and place information from json response // Create a div, and place information from json response
@@ -2457,19 +2455,19 @@ function SendHomePage() {
const title = stringToHTML( const title = stringToHTML(
'<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>' '<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>'
) )
NewNotice.append(title.firstChild) NewNotice.append(title.firstChild!)
if (NoticesPayload.payload[i].label_title !== undefined) { if (NoticesPayload.payload[i].label_title !== undefined) {
const label = stringToHTML( const label = stringToHTML(
'<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>' '<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>'
) )
NewNotice.append(label.firstChild) NewNotice.append(label.firstChild!)
} }
const staff = stringToHTML( const staff = stringToHTML(
'<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>' '<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>'
) )
NewNotice.append(staff.firstChild) NewNotice.append(staff.firstChild!)
// Converts the string into HTML // Converts the string into HTML
const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true) const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true)
for (let i = 0; i < content.childNodes.length; i++) { for (let i = 0; i < content.childNodes.length; i++) {
@@ -2489,11 +2487,11 @@ function SendHomePage() {
const colourbar = document.createElement('div') const colourbar = document.createElement('div')
colourbar.classList.add('colourbar') colourbar.classList.add('colourbar')
colourbar.style.background = 'var(--colour)' colourbar.style.background = 'var(--colour)'
NewNotice.style = `--colour: ${colour}` NewNotice.style.cssText = `--colour: ${colour}`
// Appends the colour bar to the new notice // Appends the colour bar to the new notice
NewNotice.append(colourbar) NewNotice.append(colourbar)
// Appends the new notice into the notice container // Appends the new notice into the notice container
NoticeContainer.append(NewNotice) NoticeContainer!.append(NewNotice)
} }
} }
} }
@@ -2503,9 +2501,9 @@ function SendHomePage() {
} }
} }
// Data sent as the POST request // Data sent as the POST request
const dateControl = document.querySelector('input[type="date"]') const dateControl = document.querySelector('input[type="date"]') as HTMLInputElement
xhr2.send(JSON.stringify({ date: dateControl.value })) xhr2.send(JSON.stringify({ date: dateControl!.value }))
function onInputChange (e) { function onInputChange (e: any) {
xhr2.open('POST', `${location.origin}/seqta/student/load/notices?`, true) xhr2.open('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.send(JSON.stringify({ date: e.target.value }))
@@ -2514,18 +2512,18 @@ function SendHomePage() {
const NoticesPayload = JSON.parse(xhr2.response) const NoticesPayload = JSON.parse(xhr2.response)
const NoticeContainer = document.getElementById('notice-container') const NoticeContainer = document.getElementById('notice-container')
if (NoticesPayload.payload.length === 0) { if (NoticesPayload.payload.length === 0) {
if (!NoticeContainer.innerText) { if (!NoticeContainer!.innerText) {
// If no notices: display no notices // If no notices: display no notices
const dummyNotice = document.createElement('div') const dummyNotice = document.createElement('div')
dummyNotice.textContent = 'No notices for today.' dummyNotice.textContent = 'No notices for today.'
dummyNotice.classList.add('dummynotice') dummyNotice.classList.add('dummynotice')
NoticeContainer.append(dummyNotice) NoticeContainer!.append(dummyNotice)
} }
} else { } else {
document.querySelectorAll('.notice').forEach(e => e.remove()) 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) { 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))) { if (labelArray.includes(JSON.stringify(NoticesPayload.payload[i].label))) {
@@ -2535,19 +2533,19 @@ function SendHomePage() {
const title = stringToHTML( const title = stringToHTML(
'<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>' '<h3 style="color:var(--colour)">' + NoticesPayload.payload[i].title + '</h3>'
) )
NewNotice.append(title.firstChild) NewNotice.append(title.firstChild!)
if (NoticesPayload.payload[i].label_title !== undefined) { if (NoticesPayload.payload[i].label_title !== undefined) {
const label = stringToHTML( const label = stringToHTML(
'<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>' '<h5 style="color:var(--colour)">' + NoticesPayload.payload[i].label_title + '</h5>'
) )
NewNotice.append(label.firstChild) NewNotice.append(label.firstChild!)
} }
const staff = stringToHTML( const staff = stringToHTML(
'<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>' '<h6 style="color:var(--colour)">' + NoticesPayload.payload[i].staff + '</h6>'
) )
NewNotice.append(staff.firstChild) NewNotice.append(staff.firstChild!)
// Converts the string into HTML // Converts the string into HTML
const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true) const content = stringToHTML(NoticesPayload.payload[i].contents.replace(/\[\[[\w]+[:][\w]+[\]\]]+/g, '').replace(/ +/, ' '), true)
for (let i = 0; i < content.childNodes.length; i++) { for (let i = 0; i < content.childNodes.length; i++) {
@@ -2567,11 +2565,11 @@ function SendHomePage() {
const colourbar = document.createElement('div') const colourbar = document.createElement('div')
colourbar.classList.add('colourbar') colourbar.classList.add('colourbar')
colourbar.style.background = 'var(--colour)' colourbar.style.background = 'var(--colour)'
NewNotice.style = `--colour: ${colour}` NewNotice.style.cssText = `--colour: ${colour}`
// Appends the colour bar to the new notice // Appends the colour bar to the new notice
NewNotice.append(colourbar) NewNotice.append(colourbar)
// Appends the new notice into the notice container // Appends the new notice into the notice container
NoticeContainer.append(NewNotice) NoticeContainer!.append(NewNotice)
} }
} }
} }
@@ -2584,13 +2582,13 @@ function SendHomePage() {
// Sends similar HTTP Post Request for the notices // Sends similar HTTP Post Request for the notices
const result1 = browser.storage.local.get() const result1 = browser.storage.local.get()
function open1 (result) { function open1 (result: any) {
if (result.notificationcollector) { if (result.notificationcollector) {
enableNotificationCollector(); enableNotificationCollector();
} }
} }
result1.then(open1, onError) result1.then(open1, onError)
let activeClassList; let activeClassList: any;
GetUpcomingAssessments().then((assessments) => { GetUpcomingAssessments().then((assessments) => {
GetActiveClasses().then((classes) => { GetActiveClasses().then((classes) => {
// Gets all subjects for the student // Gets all subjects for the student
@@ -2628,14 +2626,14 @@ function SendHomePage() {
}, 8); }, 8);
} }
export function addShortcuts(shortcuts) { export function addShortcuts(shortcuts: any) {
for (let i = 0; i < shortcuts.length; i++) { for (let i = 0; i < shortcuts.length; i++) {
const currentShortcut = shortcuts[i]; const currentShortcut = shortcuts[i];
if (currentShortcut?.enabled) { if (currentShortcut?.enabled) {
const Itemname = (currentShortcut?.name ?? '').replace(/\s/g, ''); const Itemname = (currentShortcut?.name ?? '').replace(/\s/g, '');
const linkDetails = ShortcutLinks?.[Itemname]; const linkDetails = ShortcutLinks?.[Itemname as keyof typeof ShortcutLinks];
if (linkDetails) { if (linkDetails) {
createNewShortcut( createNewShortcut(
linkDetails.link, linkDetails.link,
@@ -2682,16 +2680,16 @@ export function enableNotificationCollector() {
export function disableNotificationCollector() { export function disableNotificationCollector() {
var alertdiv = document.getElementsByClassName('notifications__bubble___1EkSQ')[0]; var alertdiv = document.getElementsByClassName('notifications__bubble___1EkSQ')[0];
if (typeof alertdiv != 'undefined') { if (typeof alertdiv != 'undefined') {
var currentNumber = parseInt(alertdiv.textContent); var currentNumber = parseInt(alertdiv.textContent!);
if (currentNumber < 9) { if (currentNumber < 9) {
alertdiv.textContent = currentNumber; alertdiv.textContent = currentNumber.toString();
} else { } else {
alertdiv.textContent = '9+'; alertdiv.textContent = '9+';
} }
} }
} }
function createNewShortcut(link, icon, viewBox, title) { function createNewShortcut(link: any, icon: any, viewBox: any, title: any) {
// Creates the stucture and element information for each seperate shortcut // Creates the stucture and element information for each seperate shortcut
let shortcut = document.createElement('a'); let shortcut = document.createElement('a');
shortcut.setAttribute('href', link); shortcut.setAttribute('href', link);
@@ -2702,14 +2700,14 @@ function createNewShortcut(link, icon, viewBox, title) {
let image = stringToHTML( let image = stringToHTML(
`<svg style="width:39px;height:39px" viewBox="${viewBox}"><path fill="currentColor" d="${icon}" /></svg>`, `<svg style="width:39px;height:39px" viewBox="${viewBox}"><path fill="currentColor" d="${icon}" /></svg>`,
).firstChild; ).firstChild;
image.classList.add('shortcuticondiv'); (image! as HTMLElement).classList.add('shortcuticondiv');
let text = document.createElement('p'); let text = document.createElement('p');
text.textContent = title; text.textContent = title;
shortcutdiv.append(image); shortcutdiv.append(image as HTMLElement);
shortcutdiv.append(text); shortcutdiv.append(text);
shortcut.append(shortcutdiv); shortcut.append(shortcutdiv);
document.getElementById('shortcuts').appendChild(shortcut); document.getElementById('shortcuts')!.appendChild(shortcut);
} }
function SendNewsPage() { function SendNewsPage() {
@@ -2720,11 +2718,11 @@ function SendNewsPage() {
var element = document.querySelector('[data-key=news]'); var element = document.querySelector('[data-key=news]');
// 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 = '';
// 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 htmlStr = '<div class="home-root"><div class="home-container" id="news-container"><h1 class="border">Latest Headlines - ABC News</h1></div></div>'; var htmlStr = '<div class="home-root"><div class="home-container" id="news-container"><h1 class="border">Latest Headlines - ABC News</h1></div></div>';
@@ -2732,16 +2730,16 @@ function SendNewsPage() {
var html = stringToHTML(htmlStr); var html = stringToHTML(htmlStr);
// 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!);
const titlediv = document.getElementById('title').firstChild; const titlediv = document.getElementById('title')!.firstChild;
titlediv.innerText = 'News'; (titlediv! as HTMLElement).innerText = 'News';
AppendLoadingSymbol('newsloading', '#news-container'); AppendLoadingSymbol('newsloading', '#news-container');
browser.runtime.sendMessage({ type: 'sendNews' }, function (response) { browser.runtime.sendMessage({ type: 'sendNews' }).then(function (response) {
let newsarticles = response.news.articles; let newsarticles = response.news.articles;
var newscontainer = document.querySelector('#news-container'); var newscontainer = document.querySelector('#news-container');
document.getElementById('newsloading').remove(); document.getElementById('newsloading')!.remove();
for (let i = 0; i < newsarticles.length; i++) { for (let i = 0; i < newsarticles.length; i++) {
let newsarticle = document.createElement('a'); let newsarticle = document.createElement('a');
newsarticle.classList.add('NewsArticle'); newsarticle.classList.add('NewsArticle');
@@ -2776,7 +2774,7 @@ function SendNewsPage() {
newsarticle.append(articleimage); newsarticle.append(articleimage);
newsarticle.append(articletext); newsarticle.append(articletext);
newscontainer.append(newsarticle); newscontainer!.append(newsarticle);
} }
}); });
}, 8); }, 8);
@@ -2785,7 +2783,7 @@ function SendNewsPage() {
async function CheckForMenuList() { async function CheckForMenuList() {
if (!MenuItemMutation) { if (!MenuItemMutation) {
try { try {
if (document.getElementById('menu').firstChild) { if (document.getElementById('menu')!.firstChild) {
ObserveMenuItemPosition(); ObserveMenuItemPosition();
MenuItemMutation = true; MenuItemMutation = true;
} }
@@ -2797,7 +2795,7 @@ async function CheckForMenuList() {
function documentTextColor () { function documentTextColor () {
const result = browser.storage.local.get(['DarkMode']) const result = browser.storage.local.get(['DarkMode'])
function changeDocTextCol (result) { function changeDocTextCol (result: any) {
const Darkmode = result.DarkMode const Darkmode = result.DarkMode
if (Darkmode) { if (Darkmode) {
const documentArray = document.querySelectorAll('td:not([class^="colourBar"]):not([class^="title"])') const documentArray = document.querySelectorAll('td:not([class^="colourBar"]):not([class^="title"])')
@@ -2834,7 +2832,7 @@ browser.storage.onChanged.addListener(documentTextColor)
function LoadInit() { function LoadInit() {
console.log('[BetterSEQTA] Started Init'); console.log('[BetterSEQTA] Started Init');
const result = browser.storage.local.get() const result = browser.storage.local.get()
function open (result) { function open (result: any) {
if (result.onoff) { if (result.onoff) {
SendHomePage(); SendHomePage();
} }