clean up main function

This commit is contained in:
SethBurkart123
2023-11-14 17:39:18 +11:00
parent 8dbc138638
commit 6027df5530
+60 -56
View File
@@ -1,4 +1,4 @@
/*global chrome*/ /* global chrome */
import { animate, spring, stagger } from 'motion'; import { animate, spring, stagger } from 'motion';
import Color from 'color'; import Color from 'color';
@@ -25,6 +25,45 @@ let currentSelectedDate = new Date();
let LessonInterval; let LessonInterval;
export let DarkMode; export let DarkMode;
var MenuItemMutation = false;
var NonSEQTAPage = false;
var IsSEQTAPage = false;
document.addEventListener(
'load',
function () {
CheckForMenuList();
if (
document.childNodes[1].textContent?.includes(
'Copyright (c) SEQTA Software',
) &&
document.title.includes('SEQTA Learn') &&
!IsSEQTAPage
) {
IsSEQTAPage = true;
console.log('[BetterSEQTA+] Verified SEQTA Page');
let link = document.createElement('link');
link.href = chrome.runtime.getURL('inject/documentload.css');
link.type = 'text/css';
link.rel = 'stylesheet';
document.getElementsByTagName('html')[0].appendChild(link);
enableCurrentTheme();
chrome.storage.local.get(null, function (items) {
main(items);
});
}
if (
!document.childNodes[1].textContent?.includes('SEQTA') &&
!NonSEQTAPage
) {
NonSEQTAPage = true;
}
},
true,
);
function delay(ms) { function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} }
@@ -643,38 +682,41 @@ export async function ObserveMenuItemPosition() {
} }
function main(storedSetting) { function main(storedSetting) {
const { onoff } = storedSetting;
DarkMode = storedSetting.DarkMode; DarkMode = storedSetting.DarkMode;
// If the option is 'on', open BetterSEQTA
if (typeof storedSetting.onoff == 'undefined') { // Handle undefined onoff setting
if (typeof onoff === 'undefined') {
chrome.runtime.sendMessage({ type: 'setDefaultStorage' }); chrome.runtime.sendMessage({ type: 'setDefaultStorage' });
} }
if (storedSetting.onoff) {
console.log('[BetterSEQTA+] Enabled'); const initialize = () => {
InjectStyles(); InjectStyles();
InjectCustomIcons(); InjectCustomIcons();
updateAllColors(storedSetting); updateAllColors(storedSetting);
ApplyCSSToHiddenMenuItems(); ApplyCSSToHiddenMenuItems();
loading(); loading();
CheckLoadOnPeriods(); CheckLoadOnPeriods();
};
if (!isChrome || isChrome == 'undefined') { const handleDisabled = () => {
waitForElm('.code').then(AppendElementsToDisabledPage);
};
if (onoff) {
console.log('[BetterSEQTA+] Enabled');
initialize();
if (!isChrome || isChrome === 'undefined') {
tryLoad(); tryLoad();
} }
window.addEventListener('load', function () { window.addEventListener('load', tryLoad);
tryLoad();
});
} else { } else {
if (!isChrome || isChrome == 'undefined') { if (!isChrome || isChrome === 'undefined') {
waitForElm('.code').then(() => { handleDisabled();
AppendElementsToDisabledPage();
});
} }
window.addEventListener('load', function () { window.addEventListener('load', handleDisabled);
waitForElm('.code').then(() => {
AppendElementsToDisabledPage();
});
});
} }
} }
@@ -749,44 +791,6 @@ async function CheckLoadOnPeriods() {
} }
} }
var MenuItemMutation = false;
var NonSEQTAPage = false;
var IsSEQTAPage = false;
document.addEventListener(
'load',
function () {
CheckForMenuList();
if (
document.childNodes[1].textContent?.includes(
'Copyright (c) SEQTA Software',
) &&
document.title.includes('SEQTA Learn') &&
!IsSEQTAPage
) {
IsSEQTAPage = true;
console.log('[BetterSEQTA+] Verified SEQTA Page');
var link = document.createElement('link');
link.href = chrome.runtime.getURL('inject/documentload.css');
link.type = 'text/css';
link.rel = 'stylesheet';
document.getElementsByTagName('html')[0].appendChild(link);
enableCurrentTheme();
chrome.storage.local.get(null, function (items) {
main(items);
});
}
if (
!document.childNodes[1].textContent?.includes('SEQTA') &&
!NonSEQTAPage
) {
NonSEQTAPage = true;
}
},
true,
);
export function closeSettings() { export function closeSettings() {
var extensionsettings = document.getElementById('ExtensionPopup'); var extensionsettings = document.getElementById('ExtensionPopup');