馃悕馃悕馃悕
at dev 34 lines 918 B view raw
1 2function checkForParentTheme(element, theme) { 3 let parent = element.parentElement; 4 while (parent) { 5 //if (parent.classList.contains("target")) { 6 const parentTheme = parent.getAttribute("theme"); 7 //if (!parentTheme) return false; 8 if (parentTheme) 9 return parentTheme !== theme; 10 //} 11 parent = parent.parentElement; 12 } 13 14 return false; 15} 16 17export function main(target, initialTheme = null) { 18 const storedTheme = localStorage.getItem("theme"); 19 let theme = initialTheme || storedTheme || "blackboard"; 20 target.setAttribute("theme", theme); 21 22 if (target === document.body) { 23 localStorage.setItem("theme", theme); 24 } 25 26 if (checkForParentTheme(target, theme)) { 27 target.setAttribute("theme-changed", ""); 28 } else { 29 target.removeAttribute("theme-changed"); 30 } 31 32 return { replace: false }; 33} 34