schoolbox web extension :)
0
fork

Configure Feed

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

fix(hot reload): don't inject plugins if required elements are not present

willow 9036ba92 bf5d50a2

+5 -4
+5 -4
src/utils/plugin.ts
··· 24 24 const urls = (await schoolboxUrls.storage.getValue()).urls; 25 25 26 26 if (plugin && typeof window !== "undefined" && urls.includes(window.location.origin)) { 27 + const allElementsPresent = () => elementsToWaitFor.every((selector) => document.querySelector(selector) !== null); 28 + 27 29 const inject = () => { 28 30 if (injected) return; 31 + if (!allElementsPresent) return; 29 32 logger.info(`injecting plugin: ${plugins[pluginId].name}`); 30 33 injectCallback(getSettingsValues(plugins[pluginId]?.settings)); 31 34 injected = true; ··· 77 80 if (elementsToWaitFor.length > 0) { 78 81 // create an observer to wait for all elements to be loaded 79 82 const observer = new MutationObserver((_mutations, observer) => { 80 - const allElementsPresent = elementsToWaitFor.every((selector) => document.querySelector(selector) !== null); 81 - if (allElementsPresent) { 83 + if (allElementsPresent()) { 82 84 observer.disconnect(); 83 85 inject(); 84 86 } ··· 86 88 observer.observe(document.body, { childList: true, subtree: true }); 87 89 88 90 // check if elements are already present 89 - const allElementsPresent = elementsToWaitFor.every((selector) => document.querySelector(selector) !== null); 90 - if (allElementsPresent) { 91 + if (allElementsPresent()) { 91 92 observer.disconnect(); 92 93 inject(); 93 94 }