Skip to content

Commit 3be7dd6

Browse files
author
HarithKavish
committed
Improve theme detection with system preference fallback
1 parent 95a8005 commit 3be7dd6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

docs/index.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Multi-Object Detection using YOLO</title>
8-
<!-- Theme detection before any rendering -->
8+
9+
<!-- Theme detection - BEFORE CSS to prevent flash -->
910
<script>
10-
const theme = localStorage.getItem('theme');
11-
if (theme === 'dark') {
12-
document.documentElement.classList.add('dark');
13-
}
11+
(function () {
12+
const savedTheme = localStorage.getItem('theme');
13+
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
14+
15+
if (savedTheme === 'dark' || (prefersDark && !savedTheme)) {
16+
document.documentElement.classList.add('dark');
17+
}
18+
})();
1419
</script>
20+
1521
<link rel="stylesheet" href="style.css">
1622
<!-- Load TensorFlow.js and COCO-SSD -->
1723
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>

0 commit comments

Comments
 (0)