Skip to content

Commit 34b87cf

Browse files
committed
minor changes (C) whatthecommit.com
1 parent c76b884 commit 34b87cf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

css-theme/src/app.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ WebFont.load({
1111
const light: HTMLLinkElement = document.querySelector('#light');
1212
const dark: HTMLLinkElement = document.querySelector('#dark');
1313

14-
const theme: string = localStorage.getItem('theme');
1514
const body: HTMLElement = document.body;
16-
const defaultTheme: string = 'dark';
17-
18-
body.classList.add(!theme ? defaultTheme : theme);
1915

20-
dark.onclick = e => {
16+
const usedDarkTheme = _ => {
2117
body.classList.remove('light');
2218
body.classList.add('dark');
2319
localStorage.setItem('theme', 'dark');
2420
};
2521

26-
light.onclick = e => {
22+
const useLightTheme = _ => {
2723
body.classList.replace('dark', 'light');
2824
localStorage.setItem('theme', 'light');
2925
};
26+
27+
const theme: string = localStorage.getItem('theme');
28+
29+
if (!theme && !body.classList.contains(theme))
30+
body.classList.add(theme);
31+
32+
dark.onclick = usedDarkTheme;
33+
light.onclick = useLightTheme;

0 commit comments

Comments
 (0)