Show dark version of site when prefers-color-scheme:dark (#8921)

This commit is contained in:
Vadim Klimenko 2019-09-06 13:30:17 +03:00 committed by Usha Mandya
parent 71c3891877
commit ec3da7c84d
1 changed files with 6 additions and 5 deletions

View File

@ -223,7 +223,10 @@ function eraseCookie(name) {
createCookie(name,"",-1);
}
if (readCookie("night") == "true") {
var prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
var selectedNightTheme = readCookie("night");
if (selectedNightTheme == "true" || (selectedNightTheme === null && prefersDark)) {
applyNight();
$('#switch-style').prop('checked', true);
} else {
@ -344,8 +347,7 @@ $('ul.nav li.dropdown').hover(function() {
// document.getElementById('pagestyle').setAttribute('href', sheet);
// }
function applyNight()
{
function applyNight() {
$( "body" ).addClass( "night" );
}
@ -360,8 +362,7 @@ $('#switch-style').change(function() {
createCookie("night",true,999)
} else {
applyDay();
// swapStyleSheet('/css/style.css');
eraseCookie("night")
createCookie("night",false,999);
}
});