Skip to content

Commit

Permalink
add localStorage functions to remember if page should start in dark t…
Browse files Browse the repository at this point in the history
…heme
  • Loading branch information
JG916 committed Oct 2, 2017
1 parent 9964f86 commit 3211566
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ var OSGC = window.OSGC = {};
function toggleDarkTheme() {
if (document.body.classList.contains('darkTheme')) {
document.body.classList.remove('darkTheme');
localStorage.setItem('startInDarkTheme', 'false')
} else {
document.body.classList.add('darkTheme');
localStorage.setItem('startInDarkTheme', 'true')
}
}

Expand Down
17 changes: 17 additions & 0 deletions static/startInDarkMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function toggleDarkTheme() {
if (document.body.classList.contains('darkTheme')) {
document.body.classList.remove('darkTheme');
localStorage.setItem('startInDarkTheme', 'false')
} else {
document.body.classList.add('darkTheme');
localStorage.setItem('startInDarkTheme', 'true')
}
}

function checkIfShouldStartInDarkTheme() {
if (localStorage.getItem('startInDarkTheme') === 'true') {
toggleDarkTheme();
}
}

checkIfShouldStartInDarkTheme();

0 comments on commit 3211566

Please sign in to comment.