schoolbox web extension :)
0
fork

Configure Feed

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

fix(hot reload): injecting on external sites

* close #319

willow 9bca5997 5f358eb4

+21 -9
+8 -6
src/entrypoints/start.content.ts
··· 5 5 injectLogo, 6 6 injectStylesheet, 7 7 injectUserSnippet, 8 + onSchoolboxPage, 8 9 uninjectCatppuccin, 9 10 uninjectStylesheet, 10 11 uninjectUserSnippet, 11 12 } from "@/utils"; 12 13 import { EXCLUDE_MATCHES, LOGO_INFO } from "@/utils/constants"; 13 14 import type { LogoId, Settings } from "@/utils/storage"; 14 - import { globalSettings, schoolboxUrls } from "@/utils/storage"; 15 + import { globalSettings } from "@/utils/storage"; 15 16 import type { WatchCallback } from "wxt/utils/storage"; 16 17 import cssUrl from "./catppuccin.css?url"; 17 18 ··· 21 22 runAt: "document_start", 22 23 excludeMatches: EXCLUDE_MATCHES, 23 24 async main() { 24 - const settings = await globalSettings.get(); 25 - const urls = (await schoolboxUrls.get()).urls; 25 + // if not on Schoolbox page 26 + if (!(await onSchoolboxPage())) return; 26 27 27 - const updateThemes: WatchCallback<Settings> = (newValue, oldValue) => { 28 + const updateThemes: WatchCallback<Settings> = async (newValue, oldValue) => { 28 29 // if global or themes was changed 29 30 if (hasChanged(newValue, oldValue, ["global", "themes", "themeFlavour", "themeAccent"])) { 30 31 if (newValue.global && newValue.themes) { ··· 37 38 } 38 39 }; 39 40 40 - const updateUserSnippets: WatchCallback<Settings> = (newValue, oldValue) => { 41 + const updateUserSnippets: WatchCallback<Settings> = async (newValue, oldValue) => { 41 42 // if global or userSnippets were changed 42 43 if (hasChanged(newValue, oldValue, ["global", "userSnippets"])) { 43 44 // uninject removed snippets ··· 70 71 updateUserSnippets(newValue, oldValue); 71 72 }); 72 73 73 - if (settings.global && urls.includes(window.location.origin)) { 74 + const settings = await globalSettings.get(); 75 + if (settings.global && (await onSchoolboxPage())) { 74 76 // inject themes 75 77 if (settings.themes) { 76 78 injectThemes();
+5 -1
src/utils/index.ts
··· 2 2 import { flavorEntries } from "@catppuccin/palette"; 3 3 import { logger } from "./logger"; 4 4 import type { LogoInfo } from "./storage"; 5 - import { globalSettings } from "./storage"; 5 + import { globalSettings, schoolboxUrls } from "./storage"; 6 6 7 7 export const dataAttr = (id: string) => `[data-schooltape="${id}"]`; 8 8 export function setDataAttr(el: HTMLElement, id: string) { 9 9 el.dataset.schooltape = id; 10 + } 11 + 12 + export async function onSchoolboxPage(): Promise<boolean> { 13 + return (await schoolboxUrls.get()).urls.includes(window.location.origin); 10 14 } 11 15 12 16 export function injectInlineStyles(styleText: string, id: string) {
+4 -1
src/utils/plugin.ts
··· 1 1 import { storage } from "#imports"; 2 - import { hasChanged } from "."; 2 + import { hasChanged, onSchoolboxPage } from "."; 3 3 import { logger } from "./logger"; 4 4 import type { Toggle } from "./storage"; 5 5 import { globalSettings } from "./storage"; ··· 49 49 } 50 50 51 51 async init() { 52 + // if not on Schoolbox page 53 + if (!(await onSchoolboxPage())) return; 54 + 52 55 logger.info(`init plugin: ${this.meta.name}`); 53 56 54 57 if (await this.isEnabled()) {
+4 -1
src/utils/snippet.ts
··· 1 1 import { storage } from "#imports"; 2 - import { hasChanged, injectInlineStyles, uninjectInlineStyles } from "."; 2 + import { hasChanged, injectInlineStyles, onSchoolboxPage, uninjectInlineStyles } from "."; 3 3 import { logger } from "./logger"; 4 4 import type { Toggle } from "./storage"; 5 5 import { globalSettings } from "./storage"; ··· 27 27 } 28 28 29 29 async init() { 30 + // if not on Schoolbox page 31 + if (!(await onSchoolboxPage())) return; 32 + 30 33 logger.info(`init snippet: ${this.meta.name}`); 31 34 32 35 if (await this.isEnabled()) this.inject();