Skip to content

Commit

Permalink
add initial dark mode
Browse files Browse the repository at this point in the history
fixes #21

Co-authored By: ahmadileham <[email protected]>
  • Loading branch information
Dexus committed Jan 8, 2025
1 parent 07fc45e commit 93c0250
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 30 deletions.
3 changes: 3 additions & 0 deletions main/img/dark_mode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 27 additions & 13 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,42 @@
const svgPreProcessor = require('@deepnest/svg-preprocessor');

ready(async function () {
// check for dark mode preference
const darkMode = localStorage.getItem('darkMode') === 'true';
if (darkMode) {
document.body.classList.add('dark-mode');
}

// main navigation
var tabs = document.querySelectorAll('#sidenav li');

Array.from(tabs).forEach(tab => {
tab.addEventListener('click', function (e) {
if (this.className == 'active' || this.className == 'disabled') {
return false;
}
// darkmode handler
if(this.id == 'darkmode_tab'){
document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', document.body.classList.contains('dark-mode'));
} else {

if (this.className == 'active' || this.className == 'disabled') {
return false;
}

var activetab = document.querySelector('#sidenav li.active');
activetab.className = '';
var activetab = document.querySelector('#sidenav li.active');
activetab.className = '';

var activepage = document.querySelector('.page.active');
activepage.className = 'page';
var activepage = document.querySelector('.page.active');
activepage.className = 'page';

this.className = 'active';
tabpage = document.querySelector('#' + this.dataset.page);
tabpage.className = 'page active';
this.className = 'active';
tabpage = document.querySelector('#' + this.dataset.page);
tabpage.className = 'page active';

if (tabpage.getAttribute('id') == 'home') {
resize();
if (tabpage.getAttribute('id') == 'home') {
resize();
}
return false;
}
return false;
});
});

Expand Down Expand Up @@ -1718,6 +1731,7 @@
<li id="config_tab" data-page="config"></li>
<!--<li id="account_tab" data-page="account"></li>-->
<li id="info_tab" data-page="info"></li>
<li id="darkmode_tab"></li>
</ul>

<div id="home" class="page active">
Expand Down
Loading

0 comments on commit 93c0250

Please sign in to comment.