Skip to content

Commit

Permalink
move scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kritzl committed Jul 16, 2024
1 parent 253822a commit 3b4c6cf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
36 changes: 36 additions & 0 deletions src/vinywaji/gui/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,39 @@ document.querySelectorAll("form.js-submit")
form.reset()
location.reload()
}));

let mode = localStorage.theme ?? 'system';

function updateMode() {
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}

document.querySelector('#modeSwitch > [data-icon]').dataset.icon = mode;
}

updateMode();

function switchMode() {
switch (mode) {
case 'light':
localStorage.theme = 'dark';
mode = 'dark';
break;
case 'dark':
localStorage.removeItem('theme')
mode = 'system';
break;
case 'system':
localStorage.theme = 'light';
mode = 'light';
break;
}
updateMode();
}

document.querySelector('#modeSwitch').addEventListener('click', (e) => {
switchMode();
})
36 changes: 0 additions & 36 deletions src/vinywaji/gui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,6 @@
{% include "components/footer.html" %}
{% block scripts %}
<script type="application/javascript" src="{% static 'base.js' %}"></script>
<script>
let mode = localStorage.theme ?? 'system';

function updateMode() {
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}

document.querySelector('#modeSwitch > [data-icon]').dataset.icon = mode;
}
updateMode();

function switchMode() {
switch (mode) {
case 'light':
localStorage.theme = 'dark';
mode = 'dark';
break;
case 'dark':
localStorage.removeItem('theme')
mode = 'system';
break;
case 'system':
localStorage.theme = 'light';
mode = 'light';
break;
}
updateMode();
}

document.querySelector('#modeSwitch').addEventListener('click', (e) => {
switchMode();
})
</script>
{% block scripts-extra %}{% endblock %}
{% endblock %}
{% endblock %}
Expand Down

0 comments on commit 3b4c6cf

Please sign in to comment.