MCPcopy Create free account
hub / github.com/error311/FileRise / bindDarkMode

Function bindDarkMode

public/js/main.js:905–929  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

903}
904
905function bindDarkMode() {
906 const btn = document.getElementById('darkModeToggle');
907 if (btn && !btn.__bound) {
908 btn.__bound = true;
909 applyDarkMode(); // apply once on boot
910
911 btn.addEventListener('click', () => {
912 // Toggle relative to current DOM state
913 const isDarkNext = !(document.documentElement.classList.contains('dark-mode') || document.body.classList.contains('dark-mode'));
914 try { localStorage.setItem('darkMode', isDarkNext ? '1' : '0'); } catch (e) { }
915 applyDarkMode();
916 });
917 }
918
919 // Listen to system changes only if user has NOT set a preference
920 if (!window.__FR_FLAGS.wired.sysDarkMO) {
921 window.__FR_FLAGS.wired.sysDarkMO = true;
922 let stored = null; try { stored = localStorage.getItem('darkMode'); } catch (e) { }
923 if (stored === null && window.matchMedia) {
924 const mq = window.matchMedia('(prefers-color-scheme: dark)');
925 const handler = () => applyDarkMode({ fromSystemChange: true });
926 try { mq.addEventListener('change', handler); } catch (e) { mq.addListener(handler); }
927 }
928 }
929}
930
931(function () {
932 // ---------- tiny utils ----------

Callers 2

bootHeavyFunction · 0.85
main.jsFile · 0.85

Calls 1

applyDarkModeFunction · 0.85

Tested by

no test coverage detected