Update index.js
• Light/Dark mode • New colour scheme
Alessandro committed
Sep 21, 2024 at 04:26 UTC
39c33deb74f1f50f56fb6b286630a37e931b7fa0
1 file changed
+17
-2
webui/index.js
+17
-2
@@ -230,6 +230,21 @@ window.toggleThoughts = async function (showThoughts) {
230
toggleCssProperty('.msg-thoughts', 'display', showThoughts ? undefined : 'none');
231
}
232
233
+window.toggleDarkMode = function(isDark) {
234
+ if (isDark) {
235
+ document.body.classList.remove('light-mode');
236
+ } else {
237
+ document.body.classList.add('light-mode');
238
+ }
239
+ console.log("Dark mode:", isDark);
240
+ localStorage.setItem('darkMode', isDark);
241
+ };
242
+
243
+ // Modify this part
244
+ document.addEventListener('DOMContentLoaded', () => {
245
+ const isDarkMode = localStorage.getItem('darkMode') === 'true';
246
+ toggleDarkMode(isDarkMode);
247
+ });
248
249
function toggleCssProperty(selector, property, value) {
250
// Get the stylesheet that contains the class
@@ -245,9 +260,9 @@ function toggleCssProperty(selector, property, value) {
260
if (rule.selectorText == selector) {
261
// Check if the property is already applied
262
if (value === undefined) {
248
- rule.style.removeProperty(property); // Remove the property
263
+ rule.style.removeProperty(property);
264
} else {
250
- rule.style.setProperty(property, value); // Add the property (you can customize the value)
265
+ rule.style.setProperty(property, value);
266
}
267
return;
268
}