From 4aa5aef77564f3af594697c9abf06952f0fdf227 Mon Sep 17 00:00:00 2001 From: wukko Date: Sun, 12 May 2024 17:31:33 +0600 Subject: [PATCH] web/cobalt.js: clean up --- src/front/cobalt.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/front/cobalt.js b/src/front/cobalt.js index 8b24464d..82fcfc58 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -151,13 +151,6 @@ const preferredColorScheme = () => { return theme } -if (window.matchMedia) { - window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', () => { - changeStatusBarColor() - detectColorScheme() - }) -} - const changeStatusBarColor = () => { const theme = preferredColorScheme(); const colors = { @@ -176,10 +169,15 @@ const changeStatusBarColor = () => { document.querySelector('meta[name="theme-color"]').setAttribute('content', colors[state]); } const detectColorScheme = () => { - let theme = preferredColorScheme(); + document.documentElement.setAttribute("data-theme", preferredColorScheme()); + changeStatusBarColor(); +} - document.documentElement.setAttribute("data-theme", theme); - changeStatusBarColor(theme); +if (window.matchMedia) { + window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', () => { + changeStatusBarColor() + detectColorScheme() + }) } const updateFilenamePreview = () => {