clean up main function

This commit is contained in:
SethBurkart123
2023-11-14 17:39:18 +11:00
parent 8dbc138638
commit 6027df5530
+59 -55
View File
@@ -25,6 +25,45 @@ let currentSelectedDate = new Date();
let LessonInterval;
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) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
@@ -643,38 +682,41 @@ export async function ObserveMenuItemPosition() {
}
function main(storedSetting) {
const { onoff } = storedSetting;
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' });
}
if (storedSetting.onoff) {
console.log('[BetterSEQTA+] Enabled');
const initialize = () => {
InjectStyles();
InjectCustomIcons();
updateAllColors(storedSetting);
ApplyCSSToHiddenMenuItems();
loading();
CheckLoadOnPeriods();
};
if (!isChrome || isChrome == 'undefined') {
const handleDisabled = () => {
waitForElm('.code').then(AppendElementsToDisabledPage);
};
if (onoff) {
console.log('[BetterSEQTA+] Enabled');
initialize();
if (!isChrome || isChrome === 'undefined') {
tryLoad();
}
window.addEventListener('load', function () {
tryLoad();
});
window.addEventListener('load', tryLoad);
} else {
if (!isChrome || isChrome == 'undefined') {
waitForElm('.code').then(() => {
AppendElementsToDisabledPage();
});
if (!isChrome || isChrome === 'undefined') {
handleDisabled();
}
window.addEventListener('load', function () {
waitForElm('.code').then(() => {
AppendElementsToDisabledPage();
});
});
window.addEventListener('load', handleDisabled);
}
}
@@ -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() {
var extensionsettings = document.getElementById('ExtensionPopup');