From 5c0044a4d4fa2ee26ff769994e0ffd39d262e8cc Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Mon, 17 Mar 2025 15:06:26 +1100 Subject: [PATCH] feat: cleanup work on plugins system --- src/SEQTA.ts | 10 ++--- src/plugins/hello.ts | 3 -- src/plugins/index.ts | 2 +- src/plugins/monofile.ts | 83 +---------------------------------------- src/plugins/themes.ts | 5 +++ src/seqta/main.ts | 49 ++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 93 deletions(-) delete mode 100644 src/plugins/hello.ts create mode 100644 src/plugins/themes.ts create mode 100644 src/seqta/main.ts diff --git a/src/SEQTA.ts b/src/SEQTA.ts index 7ffd0cc1..9712adf4 100644 --- a/src/SEQTA.ts +++ b/src/SEQTA.ts @@ -1,6 +1,5 @@ import { - initializeSettingsState, settingsState, } from "@/seqta/utils/listeners/SettingsState" import documentLoadCSS from "@/css/documentload.scss?inline" @@ -21,9 +20,8 @@ if (document.childNodes[1]) { init() } -import * as plugins from "@/plugins" // Import the plugins from folder - - +import * as plugins from "@/plugins" +import { main } from "@/seqta/main" async function init() { const hasSEQTATitle = document.title.includes("SEQTA Learn") @@ -40,14 +38,12 @@ async function init() { icon.href = icon48 // Change the icon try { - // wait until settingsState has been loaded from storage - await initializeSettingsState() + await main() if (settingsState.onoff) { Object.values(plugins).forEach(plugin => { plugin(); }) - } console.info( "[BetterSEQTA+] Successfully initalised BetterSEQTA+, starting to load assets.", diff --git a/src/plugins/hello.ts b/src/plugins/hello.ts deleted file mode 100644 index 6eade5c2..00000000 --- a/src/plugins/hello.ts +++ /dev/null @@ -1,3 +0,0 @@ -export async function init() { - console.log('Hello, world!') -} \ No newline at end of file diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 6b498f25..0e84ec2e 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,2 +1,2 @@ export { init as Monofile } from './monofile' -export { init as Hello } from './hello' \ No newline at end of file +export { init as Themes } from './themes' \ No newline at end of file diff --git a/src/plugins/monofile.ts b/src/plugins/monofile.ts index ca26d42e..59470914 100644 --- a/src/plugins/monofile.ts +++ b/src/plugins/monofile.ts @@ -10,7 +10,6 @@ import { delay } from "@/seqta/utils/delay" import stringToHTML from "@/seqta/utils/stringToHTML" import { MessageHandler } from "@/seqta/utils/listeners/MessageListener" import { - initializeSettingsState, settingsState, } from "@/seqta/utils/listeners/SettingsState" import { StorageChangeHandler } from "@/seqta/utils/listeners/StorageChanges" @@ -21,9 +20,7 @@ import { eventManager } from "@/seqta/utils/listeners/EventManager" import { enableNotificationCollector } from "@/seqta/utils/CreateEnable/EnableNotificationCollector" import RegisterClickListeners from "@/seqta/utils/listeners/ClickListeners" import { AddBetterSEQTAElements } from "@/seqta/ui/AddBetterSEQTAElements" -import { enableCurrentTheme } from "@/seqta/ui/themes/enableCurrent" import { updateAllColors } from "@/seqta/ui/colors/Manager" -import pageState from "@/pageState.js?url" import loading from "@/seqta/ui/Loading" import { SendNewsPage } from "@/seqta/utils/SendNewsPage" import { loadHomePage } from "@/seqta/utils/Loaders/LoadHomePage" @@ -34,77 +31,14 @@ import MenuitemSVGKey from "@/seqta/content/MenuItemSVGKey.json" // Icons and fonts import IconFamily from "@/resources/fonts/IconFamily.woff" -import icon48 from "@/resources/icons/icon-48.png?base64" // Stylesheets import iframeCSS from "@/css/iframe.scss?raw" -import injectedCSS from "@/css/injected.scss?inline" -import documentLoadCSS from "@/css/documentload.scss?inline" - -var IsSEQTAPage = false -let hasSEQTAText = false - -// This check is placed outside of the document load event due to issues with EP (https://github.com/BetterSEQTA/BetterSEQTA-Plus/issues/84) -if (document.childNodes[1]) { - hasSEQTAText = - document.childNodes[1].textContent?.includes( - "Copyright (c) SEQTA Software", - ) ?? false - init() -} - -export async function init() { - CheckForMenuList() - const hasSEQTATitle = document.title.includes("SEQTA Learn") - - if (hasSEQTAText && hasSEQTATitle && !IsSEQTAPage) { - IsSEQTAPage = true - console.info("[BetterSEQTA+] Verified SEQTA Page") - - const documentLoadStyle = document.createElement("style") - documentLoadStyle.textContent = documentLoadCSS - document.head.appendChild(documentLoadStyle) - - const icon = document.querySelector('link[rel*="icon"]')! as HTMLLinkElement - icon.href = icon48 - - try { - // wait until settingsState has been loaded from storage - await initializeSettingsState() - - if (settingsState.onoff) { - injectMainScript() - enableCurrentTheme() - - if (typeof settingsState.assessmentsAverage == "undefined") { - settingsState.assessmentsAverage = true - } - - // TEMP FIX for bug! -> this is a hack to get the injected.css file to have HMR in development mode as this import system is currently broken with crxjs - if (import.meta.env.MODE === "development") { - import("../css/injected.scss") - } else { - const injectedStyle = document.createElement("style") - injectedStyle.textContent = injectedCSS - document.head.appendChild(injectedStyle) - } - } - console.info( - "[BetterSEQTA+] Successfully initalised BetterSEQTA+, starting to load assets.", - ) - main() - } catch (error: any) { - console.error(error) - } - } -} function SetDisplayNone(ElementName: string) { return `li[data-key=${ElementName}]{display:var(--menuHidden) !important; transition: 1s;}` } - - async function HideMenuItems(): Promise { try { let stylesheetInnerText: string = "" @@ -125,14 +59,6 @@ async function HideMenuItems(): Promise { } } - - -function injectMainScript() { - const mainScript = document.createElement("script") - mainScript.src = browser.runtime.getURL(pageState) - document.head.appendChild(mainScript) -} - export function hideSideBar() { const sidebar = document.getElementById("menu") // The sidebar element to be closed const main = document.getElementById("main") // The main content element that must be resized to fill the page @@ -173,13 +99,6 @@ export async function finishLoad() { } } - - - - - - - export function GetCSSElement(file: string) { const cssFile = browser.runtime.getURL(file) const fileref = document.createElement("link") @@ -855,7 +774,7 @@ export function showConflictPopup() { }) } -function main() { +export function init() { if (typeof settingsState.onoff === "undefined") { browser.runtime.sendMessage({ type: "setDefaultStorage" }) } diff --git a/src/plugins/themes.ts b/src/plugins/themes.ts new file mode 100644 index 00000000..83d368fa --- /dev/null +++ b/src/plugins/themes.ts @@ -0,0 +1,5 @@ +import { enableCurrentTheme } from "@/seqta/ui/themes/enableCurrent"; + +export async function init() { + enableCurrentTheme(); +} \ No newline at end of file diff --git a/src/seqta/main.ts b/src/seqta/main.ts new file mode 100644 index 00000000..5921ed6b --- /dev/null +++ b/src/seqta/main.ts @@ -0,0 +1,49 @@ +// Third-party libraries +import browser from "webextension-polyfill" + +// Internal utilities and functions +import { + initializeSettingsState, + settingsState, +} from "@/seqta/utils/listeners/SettingsState" + +// UI and theme management +import pageState from "@/pageState.js?url" + +// Stylesheets +import injectedCSS from "@/css/injected.scss?inline" + +export async function main() { + return new Promise(async (resolve, reject) => { + try { + await initializeSettingsState() + + if (settingsState.onoff) { + injectPageState() + + if (typeof settingsState.assessmentsAverage == "undefined") { + settingsState.assessmentsAverage = true + } + + // TEMP FIX for bug! -> this is a hack to get the injected.css file to have HMR in development mode as this import system is currently broken with crxjs + if (import.meta.env.MODE === "development") { + import("../css/injected.scss") + } else { + const injectedStyle = document.createElement("style") + injectedStyle.textContent = injectedCSS + document.head.appendChild(injectedStyle) + } + } + resolve(true) + } catch (error: any) { + console.error(error) + reject(error) + } + }) +} + +function injectPageState() { + const mainScript = document.createElement("script") + mainScript.src = browser.runtime.getURL(pageState) + document.head.appendChild(mainScript) +} \ No newline at end of file