mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-13 07:04:39 +00:00
clean up main function
This commit is contained in:
+61
-57
@@ -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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,7 +750,7 @@ export function AppendElementsToDisabledPage() {
|
|||||||
|
|
||||||
let settingsStyle = document.createElement('style');
|
let settingsStyle = document.createElement('style');
|
||||||
settingsStyle.innerText = `
|
settingsStyle.innerText = `
|
||||||
.addedButton {
|
.addedButton {
|
||||||
position: absolute !important;
|
position: absolute !important;
|
||||||
right: 50px;
|
right: 50px;
|
||||||
width: 35px;
|
width: 35px;
|
||||||
@@ -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');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user