|
86 | 86 | s.src = SITE + '/assets/search.js'; |
87 | 87 | document.head.appendChild(s); |
88 | 88 | } |
89 | | - // Dark mode |
| 89 | + // Dark mode via CSS class |
90 | 90 | (function() { |
91 | | - const DARK = { |
92 | | - body: 'background:#1a1a2e;color:#e0e0e0', |
93 | | - nav: 'background:#16213e;border-color:#0f3460', |
94 | | - sidebar: 'background:#16213e;border-color:#0f3460', |
95 | | - }; |
| 91 | + if (!document.getElementById('dark-mode-style')) { |
| 92 | + const style = document.createElement('style'); |
| 93 | + style.id = 'dark-mode-style'; |
| 94 | + style.textContent = ` |
| 95 | + body.dark-mode { background:#1a1a2e !important; color:#e0e0e0 !important; } |
| 96 | + body.dark-mode * { color:#e0e0e0 !important; border-color:#0f3460 !important; } |
| 97 | + body.dark-mode a { color:#4fc3f7 !important; } |
| 98 | + body.dark-mode #site-nav { background:#16213e !important; } |
| 99 | + body.dark-mode .sidebar, body.dark-mode #site-sidebar { background:#16213e !important; } |
| 100 | + body.dark-mode .pane-bar { background:#16213e !important; } |
| 101 | + body.dark-mode .editor-pane, body.dark-mode .preview-pane { border-color:#0f3460 !important; } |
| 102 | + body.dark-mode .btn-run { background:#e8b400 !important; color:#111 !important; } |
| 103 | + body.dark-mode .btn-stop { background:#333 !important; color:#e0e0e0 !important; } |
| 104 | + body.dark-mode .nav-title-top, body.dark-mode .nav-title-bottom { color:#e8b400 !important; } |
| 105 | + body.dark-mode #nav-errors-link { color:#e8b400 !important; } |
| 106 | + body.dark-mode input, body.dark-mode textarea { background:#16213e !important; } |
| 107 | + body.dark-mode .sidebar a.active { color:#e8b400 !important; } |
| 108 | + `; |
| 109 | + document.head.appendChild(style); |
| 110 | + } |
96 | 111 | function applyDark(on) { |
97 | | - document.body.setAttribute('data-dark', on ? '1' : ''); |
| 112 | + document.body.classList.toggle('dark-mode', on); |
98 | 113 | const btn = document.getElementById('nav-dark-btn'); |
99 | 114 | if (btn) { |
100 | | - btn.textContent = on ? '☀️ Light' : '🌙 Dark'; |
| 115 | + btn.textContent = on ? '\u2600\uFE0F Light' : '\uD83C\uDF19 Dark'; |
101 | 116 | btn.style.background = on ? '#16213e' : '#111'; |
102 | | - btn.style.color = on ? '#e0e0e0' : '#fff'; |
| 117 | + btn.style.color = '#fff'; |
103 | 118 | btn.style.borderColor = on ? '#0f3460' : '#333'; |
104 | 119 | } |
105 | | - const nav = document.getElementById('site-nav'); |
106 | | - const sb = document.getElementById('site-sidebar') || document.querySelector('.sidebar'); |
107 | | - if (nav) { nav.style.background = on ? '#16213e' : ''; nav.style.borderColor = on ? '#0f3460' : ''; nav.style.color = on ? '#e0e0e0' : ''; } |
108 | | - if (sb) { sb.style.background = on ? '#16213e' : ''; sb.style.color = on ? '#e0e0e0' : ''; } |
109 | | - // Make all links and muted text visible |
110 | | - document.querySelectorAll('a, .sidebar a, #site-nav a, p, span, h1, h2, h3, li, label').forEach(el => { |
111 | | - if (on) { if (!el.style.color || el.style.color === 'rgb(170, 170, 170)' || el.style.color === '#aaa') el.style.color = '#e0e0e0'; } |
112 | | - else { el.style.color = ''; } |
113 | | - }); |
114 | | - document.body.style.background = on ? '#1a1a2e' : ''; |
115 | | - document.body.style.color = on ? '#e0e0e0' : ''; |
116 | | - // Editor-specific: pane bars |
117 | | - document.querySelectorAll('.pane-bar, .editor-pane, .preview-pane').forEach(el => { |
118 | | - el.style.background = on ? '#16213e' : ''; |
119 | | - el.style.borderColor = on ? '#0f3460' : ''; |
120 | | - el.style.color = on ? '#e0e0e0' : ''; |
121 | | - }); |
| 120 | + if (window.editor && window.editor.setOption) |
| 121 | + window.editor.setOption('theme', on ? 'cppmode-dark' : 'cppmode'); |
122 | 122 | try { localStorage.setItem('darkMode', on ? '1' : '0'); } catch(e) {} |
123 | 123 | } |
124 | 124 | window.__toggleDark = function() { |
125 | | - const on = document.body.getAttribute('data-dark') !== '1'; |
126 | | - applyDark(on); |
127 | | - // Also update CodeMirror if on editor page |
128 | | - if (window.editor && window.editor.setOption) { |
129 | | - window.editor.setOption('theme', on ? 'cppmode-dark' : 'cppmode'); |
130 | | - } |
| 125 | + applyDark(!document.body.classList.contains('dark-mode')); |
131 | 126 | }; |
132 | | - // Restore preference |
133 | 127 | try { |
134 | 128 | if (localStorage.getItem('darkMode') === '1') applyDark(true); |
135 | 129 | } catch(e) {} |
|
0 commit comments