schoolbox web extension :)
0
fork

Configure Feed

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

refactor(utils/plugin): track injection state

willow a2b2cbdb 7528f353

+8 -3
+3 -3
src/utils/index.ts
··· 13 13 logger.info(`injecting styles with id ${id}`); 14 14 const style = document.createElement("style"); 15 15 style.textContent = styleText; 16 - style.dataset.schooltape = `inline-${id}`; 16 + setDataAttr(style, `inline-${id}`); 17 17 document.head.append(style); 18 18 // logger.info(`injected styles with id ${id}`); 19 19 } ··· 102 102 const link = document.createElement("link"); 103 103 link.rel = "stylesheet"; 104 104 link.href = url; 105 - link.dataset.schooltape = `stylesheet-${id}`; 105 + setDataAttr(link, `stylesheet-${id}`); 106 106 document.head.appendChild(link); 107 107 } 108 108 ··· 142 142 .then((css) => { 143 143 const style = document.createElement("style"); 144 144 style.textContent = css; 145 - style.dataset.schooltape = `userSnippet-${id}`; 145 + setDataAttr(style, `userSnippet-${id}`); 146 146 document.head.appendChild(style); 147 147 logger.info(`injected user snippet with id ${id}`); 148 148 });
+5
src/utils/plugin.ts
··· 16 16 elementsToWaitFor: string[] = [], 17 17 ) { 18 18 const plugin = await plugins[pluginId].toggle.storage.getValue(); 19 + let injected = false; 19 20 20 21 logger.info(`${plugins[pluginId].name}: ${plugin.toggle ? "enabled" : "disabled"}`); 21 22 ··· 24 25 25 26 if (plugin && typeof window !== "undefined" && urls.includes(window.location.origin)) { 26 27 const inject = () => { 28 + if (injected) return; 27 29 logger.info(`injecting plugin: ${plugins[pluginId].name}`); 28 30 injectCallback(getSettingsValues(plugins[pluginId]?.settings)); 31 + injected = true; 29 32 }; 30 33 31 34 const uninject = () => { 35 + if (!injected) return; 32 36 logger.info(`uninjecting plugin: ${plugins[pluginId].name}`); 33 37 uninjectCallback(getSettingsValues(plugins[pluginId]?.settings)); 38 + injected = false; 34 39 }; 35 40 36 41 const initWatchers = () => {