schoolbox web extension :)
0
fork

Configure Feed

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

fix: timetable labels sometimes not injecting

- use MutationObserver

Willow 3fd48427 88b299fa

+18 -6
+18 -6
src/plugins/timetable-labels/timetable-labels.js
··· 1 - const days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] 2 - if (window.location.pathname === "/timetable" && document.getElementsByClassName("timetable")[0]) { 3 - for(let i = 0; i < 7; i++) { 4 - document.querySelector(`.timetable > thead > tr > th:nth-child(${i+2})`).innerHTML = days[i] 5 - document.querySelector(`.timetable-small > div:nth-child(${i+1}) > h2`).innerHTML = days[i] 1 + const days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] 2 + 3 + const observer = new MutationObserver((mutationsList, observer) => { 4 + for(let mutation of mutationsList) { 5 + if (mutation.type === 'childList') { 6 + const timetable = document.querySelector(".timetable"); 7 + const timetableSmall = document.querySelector(".timetable-small"); 8 + if (timetable && timetableSmall) { 9 + observer.disconnect(); 10 + days.forEach((day, i) => { 11 + document.querySelector(`.timetable > thead > tr > th:nth-child(${i+2})`).innerHTML = day; 12 + document.querySelector(`.timetable-small > div:nth-child(${i+1}) > h2`).innerHTML = day; 13 + }); 14 + return; 15 + } 16 + } 6 17 } 7 - } 18 + }); 19 + observer.observe(document, { childList: true, subtree: true });