Skip to content

Commit b984e4a

Browse files
committed
fix: Add color-scheme and force meta tag recreation for Safari iOS status bar
1 parent 84a5b8d commit b984e4a

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

assets/css/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Design System & Variables
33
========================================================================= */
44
:root {
5+
color-scheme: dark;
56
/* Color Palette */
67
--bg-base: #0a0a0f;
78
--bg-surface: #12131b;
@@ -83,6 +84,10 @@
8384
Theme Overrides — Light Themes
8485
========================================================================= */
8586

87+
[data-theme$="-light"] {
88+
color-scheme: light;
89+
}
90+
8691
/* Cyber Light — cool blue-gray */
8792
[data-theme="cyber-light"] {
8893
--bg-base: #f0f4f8;

assets/js/script.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ document.addEventListener('DOMContentLoaded', () => {
126126
localStorage.setItem('theme', theme);
127127

128128
// Update meta theme-color after the CSS background transition completes
129-
// This prevents an iOS Safari bug where the status bar text color inverts
129+
// Recreating the DOM node forces Safari to update the status bar correctly
130130
setTimeout(() => {
131-
const metaThemeColor = document.querySelector('meta[name="theme-color"]');
132-
if (metaThemeColor) {
133-
metaThemeColor.setAttribute('content', themeColors[theme] || '#0a0a0f');
131+
const oldMeta = document.querySelector('meta[name="theme-color"]');
132+
if (oldMeta) {
133+
oldMeta.remove();
134134
}
135+
const newMeta = document.createElement('meta');
136+
newMeta.name = 'theme-color';
137+
newMeta.content = themeColors[theme] || '#0a0a0f';
138+
document.head.appendChild(newMeta);
135139
}, 400);
136140

137141
// Sync active state across all theme option buttons (desktop + mobile)

assets/js/theme-init.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
};
2020
if (saved && saved !== 'cyber') {
2121
document.documentElement.setAttribute('data-theme', saved);
22-
var meta = document.querySelector('meta[name="theme-color"]');
23-
if (meta) {
24-
meta.setAttribute('content', themeColors[saved] || '#0a0a0f');
22+
var oldMeta = document.querySelector('meta[name="theme-color"]');
23+
if (oldMeta) {
24+
oldMeta.parentNode.removeChild(oldMeta);
2525
}
26+
var newMeta = document.createElement('meta');
27+
newMeta.name = 'theme-color';
28+
newMeta.content = themeColors[saved] || '#0a0a0f';
29+
document.getElementsByTagName('head')[0].appendChild(newMeta);
2630
}
2731
})();

0 commit comments

Comments
 (0)