schoolbox web extension :)
0
fork

Configure Feed

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

feat(plugins/tabTitle): hot reload

willow 0cc6515f 28530125

+31 -3
+22 -1
src/entrypoints/plugins/tabTitle.ts
··· 1 + import { dataAttr, setDataAttr } from "@/utils"; 1 2 import { definePlugin } from "@/utils/plugin"; 3 + 4 + const ID = "tabTitle"; 5 + const PLUGIN_ID = `plugin-${ID}`; 2 6 3 7 export default function init() { 4 8 definePlugin( 5 - "tabTitle", 9 + ID, 6 10 async (settings) => { 11 + // if already injected, skip 12 + if (document.querySelector(`meta${dataAttr(PLUGIN_ID)}`)) return; 13 + 14 + // backup original title (used for uninjection) 15 + const meta = document.createElement("meta"); 16 + setDataAttr(meta, PLUGIN_ID); 17 + meta.name = "original-title"; // not needed but good label 18 + meta.content = document.title; 19 + document.head.appendChild(meta); 20 + 7 21 const path = window.location.pathname; 8 22 const titleMap: { [key: string]: string } = { 9 23 "/": "Homepage", ··· 42 56 } else { 43 57 document.title = document.getElementsByTagName("h1")[0].innerText; 44 58 } 59 + } 60 + }, 61 + () => { 62 + const meta = document.querySelector<HTMLMetaElement>(`meta${dataAttr(PLUGIN_ID)}`); 63 + if (meta) { 64 + document.title = meta.content; 65 + document.head.removeChild(meta); 45 66 } 46 67 }, 47 68 ["h1"],
+9 -2
src/utils/index.ts
··· 4 4 import type { LogoInfo } from "./storage"; 5 5 import { globalSettings } from "./storage"; 6 6 7 + export const dataAttr = (id: string) => `[data-schooltape="${id}"]`; 8 + export function setDataAttr(el: HTMLElement, id: string) { 9 + el.dataset.schooltape = id; 10 + } 11 + 7 12 export function schooltapeQuerySelector(id: string) { 8 - return document.querySelector(`[data-schooltape="${id}"]`); 13 + // TODO: deprecate 14 + return document.querySelector(dataAttr(id)); 9 15 } 10 16 export function schooltapeQuerySelectorAll(id: string) { 11 - return document.querySelectorAll(`[data-schooltape="${id}"]`); 17 + // TODO: deprecate 18 + return document.querySelectorAll(dataAttr(id)); 12 19 } 13 20 14 21 export function injectInlineStyles(styleText: string, id: string) {