schoolbox web extension :)
1import { dataAttr, injectInlineStyles, setDataAttr, uninjectInlineStyles } from "@/utils";
2import { Plugin } from "@/utils/plugin";
3import styleText from "./styles.css?inline";
4
5const ID = "scrollSegments";
6const PLUGIN_ID = `plugin-${ID}`;
7
8export default new Plugin(
9 {
10 id: ID,
11 name: "Scroll Segments",
12 description: "Segments the Schoolbox page into scrollable sections.",
13 },
14 true,
15 null,
16 () => {
17 const footerCopy = document.querySelector(dataAttr(PLUGIN_ID));
18 if (footerCopy) return;
19
20 // scroll to top to avoid hot reload bug
21 window.scrollTo({
22 top: 0,
23 behavior: "instant",
24 });
25
26 const content = document.querySelector("#content");
27 const footer = document.querySelector<HTMLDivElement>("#footer");
28
29 // add copy of footer to content
30 if (content && footer) {
31 const clone = footer.cloneNode(true) as HTMLDivElement;
32 setDataAttr(clone, PLUGIN_ID);
33 content.appendChild(clone);
34 }
35
36 injectInlineStyles(styleText, PLUGIN_ID);
37 },
38 () => {
39 const footerCopy = document.querySelector(dataAttr(PLUGIN_ID));
40 if (!footerCopy) return;
41
42 // remove copy of footer from content
43 const content = document.querySelector("#content");
44 content?.removeChild(footerCopy);
45
46 uninjectInlineStyles(PLUGIN_ID);
47 },
48 ["#content", "#footer"],
49);