|
32 | 32 | if(s) s.classList.toggle('open'); |
33 | 33 | ">☰</button> |
34 | 34 | <a href="${prefix}error/index.html" id="nav-errors-link"${isActive('error') ? ' class="active"' : ''}>Errors</a> |
| 35 | + <button id="nav-dark-btn" onclick="window.__toggleDark&&window.__toggleDark()" style="background:none;border:1px solid #e0e0e0;color:#555;padding:3px 10px;border-radius:4px;font-size:12px;cursor:pointer;margin-left:0.5rem;">🌙</button> |
35 | 36 | `; |
36 | 37 | } |
37 | 38 |
|
|
85 | 86 | s.src = SITE + '/assets/search.js'; |
86 | 87 | document.head.appendChild(s); |
87 | 88 | } |
| 89 | + // Dark mode |
| 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 | + }; |
| 96 | + function applyDark(on) { |
| 97 | + document.body.setAttribute('data-dark', on ? '1' : ''); |
| 98 | + const btn = document.getElementById('nav-dark-btn'); |
| 99 | + if (btn) btn.textContent = on ? '☀️' : '🌙'; |
| 100 | + const nav = document.getElementById('site-nav'); |
| 101 | + const sb = document.getElementById('site-sidebar') || document.querySelector('.sidebar'); |
| 102 | + if (nav) { nav.style.background = on ? '#16213e' : ''; nav.style.borderColor = on ? '#0f3460' : ''; } |
| 103 | + if (sb) { sb.style.background = on ? '#16213e' : ''; } |
| 104 | + document.body.style.background = on ? '#1a1a2e' : ''; |
| 105 | + document.body.style.color = on ? '#e0e0e0' : ''; |
| 106 | + try { localStorage.setItem('darkMode', on ? '1' : '0'); } catch(e) {} |
| 107 | + } |
| 108 | + window.__toggleDark = function() { |
| 109 | + const on = document.body.getAttribute('data-dark') !== '1'; |
| 110 | + applyDark(on); |
| 111 | + // Also update CodeMirror if on editor page |
| 112 | + if (window.editor && window.editor.setOption) { |
| 113 | + window.editor.setOption('theme', on ? 'cppmode-dark' : 'cppmode'); |
| 114 | + } |
| 115 | + }; |
| 116 | + // Restore preference |
| 117 | + try { |
| 118 | + if (localStorage.getItem('darkMode') === '1') applyDark(true); |
| 119 | + } catch(e) {} |
| 120 | + })(); |
88 | 121 | })(); |
0 commit comments