schoolbox web extension :)
1import { defineContentScript } from "#imports";
2import { EXCLUDE_MATCHES } from "@/utils/constants";
3import { logger } from "@/utils/logger";
4import { globalSettings, schoolboxUrls } from "@/utils/storage";
5
6export default defineContentScript({
7 matches: ["<all_urls>"],
8 runAt: "document_end",
9 excludeMatches: EXCLUDE_MATCHES,
10 async main() {
11 const settings = await globalSettings.get();
12 const urls = (await schoolboxUrls.get()).urls;
13
14 logger.info(urls);
15
16 if (!settings.global) return;
17
18 const footer = document.querySelector("#footer > ul");
19
20 if (footer && footer.innerHTML.includes("Schoolbox")) {
21 if (!urls.includes(window.location.origin)) {
22 logger.info(`URL ${window.location.origin} not in storage, adding...`);
23 urls.push(window.location.origin);
24 await schoolboxUrls.set({ urls });
25 // TODO: hot reload
26 window.location.reload();
27 }
28 }
29 },
30});