Skip to content

Commit

Permalink
Merge pull request #25 from Astrian/dev
Browse files Browse the repository at this point in the history
New colour scheme preference option, and some style adjust
  • Loading branch information
Astrian Zheng authored Aug 13, 2021
2 parents b5c8b1d + d3d4c9d commit c3a197a
Show file tree
Hide file tree
Showing 6 changed files with 1,328 additions and 200 deletions.
37 changes: 37 additions & 0 deletions asset/colorscheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
changeColorScheme()
function changeColorScheme(pref) {
if (pref) localStorage.setItem('rw-colorscheme', pref)
else pref = localStorage.getItem('rw-colorscheme')
if (!pref){
localStorage.setItem('rw-colorscheme', 'system')
pref = 'system'
}
switch (pref) {
case 'system': {
let systemColorscheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
if (systemColorscheme === 'dark') $('body').addClass('darkscheme')
else $('body').removeClass('darkscheme')
$('#colorSchemeSystem').css('font-weight', 'bold')
$('#colorSchemeDark').css('font-weight', 'normal')
$('#colorSchemeLight').css('font-weight', 'normal')
break
}
case 'dark': {
$('body').addClass('darkscheme')
$('#colorSchemeSystem').css('font-weight', 'normal')
$('#colorSchemeDark').css('font-weight', 'bold')
$('#colorSchemeLight').css('font-weight', 'normal')
break
}
case 'light': {
$('body').removeClass('darkscheme')
$('#colorSchemeSystem').css('font-weight', 'normal')
$('#colorSchemeDark').css('font-weight', 'normal')
$('#colorSchemeLight').css('font-weight', 'bold')
break
}
}
}
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
changeColorScheme()
})
Loading

0 comments on commit c3a197a

Please sign in to comment.