schoolbox web extension :)
0
fork

Configure Feed

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

feat(plugins/progressBar): hot reload

willow 7528f353 7c9536f7

+6 -15
+6 -15
src/entrypoints/plugins/progressBar/index.ts
··· 1 - import { dataAttr, injectInlineStyles, uninjectInlineStyles } from "@/utils"; 1 + import { dataAttr, injectInlineStyles, setDataAttr, uninjectInlineStyles } from "@/utils"; 2 2 import type { Period } from "@/utils/periodUtils"; 3 3 import { getListOfPeriods } from "@/utils/periodUtils"; 4 4 import { definePlugin } from "@/utils/plugin"; ··· 16 16 17 17 const progressRow = document.createElement("tr"); 18 18 progressRow.classList.add("progress-container"); 19 + setDataAttr(progressRow, `${PLUGIN_ID}-row`); 19 20 document.querySelector(".timetable > thead")?.insertAdjacentElement("beforeend", progressRow); 20 21 21 22 injectInlineStyles(styleText, PLUGIN_ID); ··· 30 31 ); 31 32 } 32 33 33 - const getProgressBars = () => document.querySelectorAll(dataAttr(PLUGIN_ID)); 34 - 35 34 function injectProgressBars(periodList: Period[], container: HTMLElement) { 36 - const progressBars = getProgressBars(); 37 - if (progressBars && progressBars.length > 0) return; 38 - 39 - periodList.forEach((period) => { 35 + for (const period of periodList) { 40 36 const td = document.createElement("td"); 41 37 const progressBar = document.createElement("progress"); 42 38 const progress = period.getProgress(); ··· 44 40 progressBar.max = 100; 45 41 progressBar.style.width = "100%"; 46 42 progressBar.value = progress; 47 - progressBar.dataset.schooltape = PLUGIN_ID; 48 43 49 44 if (progress < 100) { 50 45 const intervalId = setInterval(() => { ··· 57 52 58 53 td.appendChild(progressBar); 59 54 container.appendChild(td); 60 - }); 55 + } 61 56 } 62 57 63 58 function uninjectProgressBars() { 64 - const progressBars = getProgressBars(); 65 - if (progressBars && progressBars.length === 0) return; 66 - 67 - for (const bar of progressBars) { 68 - document.removeChild(bar); 69 - } 59 + const row = document.querySelector(dataAttr(`${PLUGIN_ID}-row`)); 60 + row?.parentElement?.removeChild(row); 70 61 }