This commit is contained in:
monerooo 2022-04-02 11:27:36 +02:00
parent 91ba1bb533
commit 2c39dffbeb
2 changed files with 11 additions and 12 deletions

View File

@ -14,5 +14,4 @@
<a href="{{ site.baseurl }}" class="wk">Weekly</a> <a href="{{ site.baseurl }}" class="wk">Weekly</a>
<a href="/periodicals/" class="pd">Periodical</a> <a href="/periodicals/" class="pd">Periodical</a>
</div> </div>
</header> </header>

View File

@ -8,21 +8,21 @@ const toggleSwitch = document.querySelector('.switch input[type="checkbox"]');
const currentTheme = localStorage.getItem('theme'); const currentTheme = localStorage.getItem('theme');
if (currentTheme) { if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme); document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') { if (currentTheme === 'dark') {
toggleSwitch.checked = true; toggleSwitch.checked = true;
} }
} }
function switchTheme(e) { function switchTheme(e) {
if (e.target.checked) { if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark'); document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark'); localStorage.setItem('theme', 'dark');
} else { } else {
document.documentElement.setAttribute('data-theme', 'light'); document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light'); localStorage.setItem('theme', 'light');
} }
} }
toggleSwitch.addEventListener('change', switchTheme, false); toggleSwitch.addEventListener('change', switchTheme, false);