MCPcopy Index your code
hub / github.com/tinyplex/tinybase / darkLoad

Function darkLoad

site/js/common/dark.ts:7–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5const AUTO = 'auto';
6
7export const darkLoad = () => {
8 const pref = matchMedia('(prefers-color-scheme: dark)');
9 const update = () => {
10 const dark = localStorage.getItem(DARK) ?? AUTO;
11 query('#dark')?.setAttribute('class', dark);
12 query('html').className =
13 dark == DARK || (dark == AUTO && pref.matches) ? DARK : LIGHT;
14 };
15 pref.addEventListener('change', update);
16 window.addEventListener('storage', (event) => {
17 if (event.storageArea == localStorage && event.key == DARK) {
18 update();
19 }
20 });
21 addEventListener('load', () => {
22 query('#dark').addEventListener('click', () => {
23 const dark = localStorage.getItem(DARK);
24 localStorage.setItem(
25 DARK,
26 dark == DARK ? LIGHT : dark == LIGHT ? AUTO : DARK,
27 );
28 update();
29 });
30 update();
31 });
32 update();
33};

Callers 3

single.tsFile · 0.90
home.tsFile · 0.90
app.tsFile · 0.90

Calls 4

queryFunction · 0.90
updateFunction · 0.85
addEventListenerMethod · 0.80
addEventListenerFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…