|
1 | 1 | // netboot.xyz |
2 | 2 | // Client side javascript |
3 | 3 |
|
| 4 | +//// Theme Management //// |
| 5 | +function initializeTheme() { |
| 6 | + const savedTheme = localStorage.getItem('netbootxyz-theme') || 'light'; |
| 7 | + applyTheme(savedTheme); |
| 8 | +} |
| 9 | + |
| 10 | +function toggleTheme() { |
| 11 | + const currentTheme = document.documentElement.getAttribute('data-theme') || 'light'; |
| 12 | + const newTheme = currentTheme === 'light' ? 'dark' : 'light'; |
| 13 | + applyTheme(newTheme); |
| 14 | + localStorage.setItem('netbootxyz-theme', newTheme); |
| 15 | +} |
| 16 | + |
| 17 | +function applyTheme(theme) { |
| 18 | + document.documentElement.setAttribute('data-theme', theme); |
| 19 | + const themeIcon = document.getElementById('theme-icon'); |
| 20 | + if (themeIcon) { |
| 21 | + themeIcon.textContent = theme === 'light' ? '🌙' : '☀️'; |
| 22 | + } |
| 23 | + |
| 24 | + // Update Ace Editor theme if it exists |
| 25 | + updateAceEditorTheme(theme); |
| 26 | +} |
| 27 | + |
| 28 | +function updateAceEditorTheme(theme) { |
| 29 | + const editorElement = document.getElementById('editor'); |
| 30 | + if (editorElement && typeof ace !== 'undefined') { |
| 31 | + try { |
| 32 | + const editor = ace.edit('editor'); |
| 33 | + const aceTheme = theme === 'dark' ? 'ace/theme/monokai' : 'ace/theme/chrome'; |
| 34 | + editor.setTheme(aceTheme); |
| 35 | + } catch (e) { |
| 36 | + // Editor might not be initialized yet, ignore |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
4 | 41 |
|
5 | 42 | // Initiate a websocket connection to the server |
6 | 43 | var host = window.location.hostname; |
7 | 44 | var port = window.location.port; |
8 | 45 | var protocol = window.location.protocol; |
9 | 46 | var socket = io.connect(protocol + '//' + host + ':' + port, {path: "<%= baseurl %>socket.io"}); |
10 | 47 | // If the page is being loaded for the first time render in the homepage |
11 | | -$(document).ready(function(){renderdash()}) |
| 48 | +$(document).ready(function(){ |
| 49 | + // Initialize theme from localStorage or default to light |
| 50 | + initializeTheme(); |
| 51 | + renderdash(); |
| 52 | +}) |
12 | 53 |
|
13 | 54 |
|
14 | 55 | //// Dashboard Page rendering //// |
@@ -212,7 +253,9 @@ socket.on('editrenderfile', function(response,filename,metadata){ |
212 | 253 | </div>\ |
213 | 254 | <div id="editor" style="height:100%;width:100%"></div>'); |
214 | 255 | editor = ace.edit('editor'); |
215 | | - editor.setTheme('ace/theme/chrome'); |
| 256 | + const currentTheme = document.documentElement.getAttribute('data-theme') || 'light'; |
| 257 | + const aceTheme = currentTheme === 'dark' ? 'ace/theme/monokai' : 'ace/theme/chrome'; |
| 258 | + editor.setTheme(aceTheme); |
216 | 259 | editor.session.setMode('ace/mode/sh'); |
217 | 260 | editor.$blockScrolling = Infinity; |
218 | 261 | editor.setOptions({ |
|
0 commit comments