mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
feat: cleanup work on plugins system
This commit is contained in:
+3
-7
@@ -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.",
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export async function init() {
|
||||
console.log('Hello, world!')
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
export { init as Monofile } from './monofile'
|
||||
export { init as Hello } from './hello'
|
||||
export { init as Themes } from './themes'
|
||||
+1
-82
@@ -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<void> {
|
||||
try {
|
||||
let stylesheetInnerText: string = ""
|
||||
@@ -125,14 +59,6 @@ async function HideMenuItems(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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" })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { enableCurrentTheme } from "@/seqta/ui/themes/enableCurrent";
|
||||
|
||||
export async function init() {
|
||||
enableCurrentTheme();
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user