schoolbox web extension :)
0
fork

Configure Feed

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

refactor(plugins/tabTitle): simplify hot reload

willow 5f7ec27f d0a8e392

+9 -14
+9 -14
src/entrypoints/plugins/tabTitle.ts
··· 1 - import { dataAttr, setDataAttr } from "@/utils"; 2 1 import { definePlugin } from "@/utils/plugin"; 3 2 4 3 const ID = "tabTitle"; 5 - const PLUGIN_ID = `plugin-${ID}`; 4 + let originalTitle: string | null = null; 6 5 7 6 export default function init() { 8 7 definePlugin( 9 8 ID, 10 9 async (settings) => { 11 - // if already injected, skip 12 - if (document.querySelector(`meta${dataAttr(PLUGIN_ID)}`)) return; 10 + // if already injected, abort 11 + if (originalTitle) return; 13 12 14 13 // 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); 14 + originalTitle = document.title; 20 15 21 16 const path = window.location.pathname; 22 17 const titleMap: { [key: string]: string } = { ··· 59 54 } 60 55 }, 61 56 () => { 62 - const meta = document.querySelector<HTMLMetaElement>(`meta${dataAttr(PLUGIN_ID)}`); 63 - if (meta) { 64 - document.title = meta.content; 65 - document.head.removeChild(meta); 66 - } 57 + // if not injected, abort 58 + if (!originalTitle) return; 59 + 60 + document.title = originalTitle; 61 + originalTitle = null; 67 62 }, 68 63 ["h1"], 69 64 );