schoolbox web extension :)
1import { getCurrentPeriod } from "@/utils/periodUtils"; 2import { definePlugin } from "@/utils/plugin"; 3 4export default function init() { 5 definePlugin( 6 "scrollPeriod", 7 async (settings) => { 8 const timetable = document.querySelector("[data-timetable-container] div.scrollable"); 9 10 if (window.location.pathname === "/" && document.getElementsByClassName("timetable")[0]) { 11 updateScrollbar(); 12 13 const cooldownDuration = settings?.slider.cooldownDuration; 14 const resetCooldownOnMouseMove = settings?.toggle.resetCooldownOnMouseMove; 15 16 let interval: string | number | NodeJS.Timeout | undefined; 17 function start() { 18 interval = setInterval(updateScrollbar, (cooldownDuration?.value || 10) * 1000); 19 } 20 function reset() { 21 if (interval) { 22 clearInterval(interval); 23 start(); 24 } 25 } 26 27 start(); 28 29 if (resetCooldownOnMouseMove === true) { 30 document.addEventListener("mousemove", reset); 31 } 32 } 33 34 function updateScrollbar() { 35 const currentPeriod = getCurrentPeriod(); 36 if (currentPeriod && currentPeriod.index && timetable) { 37 const period = document.querySelector( 38 `.timetable thead tr th:nth-child(${currentPeriod.index})`, 39 ) as HTMLElement; 40 if (period) { 41 timetable.scroll({ 42 left: period.offsetLeft - 55, // adjusted for alignment 43 behavior: "smooth", // or 'auto' for instant scroll 44 }); 45 } 46 } 47 } 48 }, 49 [".timetable"], 50 ); 51}