schoolbox web extension :)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: simplify injectPlugin callback params

willow 77aa6ab3 47450f78

+11 -16
+1 -1
src/entrypoints/plugins/homepageSwitcher.ts
··· 4 4 export default function init() { 5 5 definePlugin( 6 6 "homepageSwitcher", 7 - (_id, _data, settings) => { 7 + (settings) => { 8 8 const logos = Array.from(document.getElementsByClassName("logo")) as HTMLAnchorElement[]; 9 9 logos.forEach((logo) => { 10 10 logo.addEventListener("click", async function (e) {
+1 -1
src/entrypoints/plugins/modernIcons/index.ts
··· 5 5 export default function init() { 6 6 definePlugin( 7 7 "modernIcons", 8 - async (_id, _data, settings) => { 8 + async (settings) => { 9 9 // [className, iconName] (material icons) 10 10 const icons = { 11 11 "icon-teacher": "school",
+1 -1
src/entrypoints/plugins/scrollPeriod.ts
··· 4 4 export default function init() { 5 5 definePlugin( 6 6 "scrollPeriod", 7 - async (_id, _data, settings) => { 7 + async (settings) => { 8 8 const timetable = document.querySelector("[data-timetable-container] div.scrollable"); 9 9 10 10 if (window.location.pathname === "/" && document.getElementsByClassName("timetable")[0]) {
+1 -1
src/entrypoints/plugins/subheader.ts
··· 4 4 export default function init() { 5 5 definePlugin( 6 6 "subheader", 7 - (_id, _data, settings) => { 7 + (settings) => { 8 8 const style = document.createElement("style"); 9 9 style.classList = "schooltape"; 10 10 style.innerHTML = `
+1 -1
src/entrypoints/plugins/tabTitle.ts
··· 3 3 export default function init() { 4 4 definePlugin( 5 5 "tabTitle", 6 - async (_id, _data, settings) => { 6 + async (settings) => { 7 7 const path = window.location.pathname; 8 8 const titleMap: { [key: string]: string } = { 9 9 "/": "Homepage",
+6 -11
src/utils/plugin.ts
··· 1 1 import { logger } from "./logger"; 2 - import type { PluginData, PluginId, PluginSetting, Slider } from "./storage"; 2 + import type { PluginId, PluginSetting, Slider } from "./storage"; 3 3 import { globalSettings, plugins, schoolboxUrls } from "./storage"; 4 4 5 5 export async function definePlugin( 6 6 pluginId: PluginId, 7 - injectLogic: ( 8 - id: PluginId, 9 - data: PluginData, 10 - settings?: { 11 - toggle: Record<string, boolean>; 12 - slider: Record<string, Slider>; 13 - }, 14 - ) => Promise<void> | void, 7 + callback: (settings?: { toggle: Record<string, boolean>; slider: Record<string, Slider> }) => Promise<void> | void, 15 8 elementsToWaitFor: string[] = [], 16 9 ) { 17 10 const plugin = await plugins[pluginId].toggle.storage.getValue(); ··· 24 17 if (plugin && typeof window !== "undefined" && urls.includes(window.location.origin)) { 25 18 if (settings.global && settings.plugins && plugin.toggle) { 26 19 const injectPlugin = () => { 27 - injectLogic(pluginId, plugins[pluginId], getSettingsValues(plugins[pluginId].settings!)); 20 + callback(getSettingsValues(plugins[pluginId]?.settings)); 28 21 }; 29 22 30 23 const loadPlugin = () => { ··· 64 57 } 65 58 } 66 59 67 - function getSettingsValues(settings: Record<string, PluginSetting>) { 60 + function getSettingsValues(settings?: Record<string, PluginSetting>) { 68 61 logger.info("Getting settings values for settings:", settings); 62 + if (!settings) return undefined; 63 + 69 64 const result: { 70 65 toggle: Record<string, boolean>; 71 66 slider: Record<string, Slider>;