|
1 | 1 | (function() { |
| 2 | + // Prevent dark mode flash -- apply class before first paint |
| 3 | + try { |
| 4 | + if (localStorage.getItem('darkMode') === '1') document.documentElement.classList.add('dark-pre'); |
| 5 | + } catch(e) {} |
2 | 6 | const SITE = 'https://processing-cpp.github.io'; |
3 | 7 | const path = window.location.pathname; |
4 | 8 | const parts = path.replace(/\/$/, '').split('/').filter(Boolean); |
|
56 | 60 | const style = document.createElement('style'); |
57 | 61 | style.id = 'nav-shared-style'; |
58 | 62 | style.textContent = ` |
| 63 | + html.dark-pre body { background:#1a1a2e !important; } |
59 | 64 | #site-nav { |
60 | 65 | border-bottom: 1px solid #e0e0e0; |
61 | 66 | padding: 0 2rem; |
|
91 | 96 | if (document.querySelector('.syntax-block, .impl-block') && |
92 | 97 | !document.getElementById('ref-cm-loaded')) { |
93 | 98 | const CDNJS = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16'; |
| 99 | + // Preload hints for faster script loading |
| 100 | + [CDNJS + '/codemirror.min.js', CDNJS + '/mode/clike/clike.min.js', |
| 101 | + SITE + '/assets/cppmode-keywords.js', SITE + '/assets/cppmode.js'].forEach(href => { |
| 102 | + const l = document.createElement('link'); |
| 103 | + l.rel = 'preload'; l.as = 'script'; l.href = href; |
| 104 | + document.head.appendChild(l); |
| 105 | + }); |
94 | 106 | function loadScript(src, cb) { |
95 | 107 | const s = document.createElement('script'); s.src = src; |
96 | 108 | s.onload = cb; document.head.appendChild(s); |
|
154 | 166 | body.dark-mode .sidebar a.active { color:#e8b400 !important; font-weight:700; } |
155 | 167 | body.dark-mode #nav-dark-btn { background:#313244 !important; color:#cdd6f4 !important; border-color:#45475a !important; } |
156 | 168 | body.dark-mode .CodeMirror-gutters { background:#181825 !important; border-color:#313244 !important; } |
| 169 | + body.dark-mode #hero-preview, body.dark-mode #hero-preview iframe, |
| 170 | + body.dark-mode #logo-sketch-wrap, body.dark-mode #logo-sketch-wrap iframe { background:#1e1e2e !important; } |
157 | 171 | body.dark-mode .CodeMirror-linenumber { color:#6c7086 !important; } |
158 | 172 | body.dark-mode input, body.dark-mode select, body.dark-mode textarea { background:#181825 !important; color:#cdd6f4 !important; } |
159 | 173 | body.dark-mode ::placeholder { color:#6c7086 !important; } |
|
230 | 244 | document.querySelectorAll('.CodeMirror').forEach(el => { |
231 | 245 | if (el.CodeMirror) el.CodeMirror.setOption('theme', on ? 'cppmode-dark' : 'cppmode'); |
232 | 246 | }); |
| 247 | + // Tell sketch iframes about dark mode |
| 248 | + document.querySelectorAll('iframe').forEach(fr => { |
| 249 | + try { fr.contentWindow.postMessage(on ? 'dark' : 'light', '*'); } catch(e) {} |
| 250 | + }); |
233 | 251 | try { localStorage.setItem('darkMode', on ? '1' : '0'); } catch(e) {} |
234 | 252 | } |
235 | 253 | window.__toggleDark = function() { |
|
0 commit comments