From ec3da7c84d7e347ad256a5d9f59fd375a6fe39da Mon Sep 17 00:00:00 2001 From: Vadim Klimenko Date: Fri, 6 Sep 2019 13:30:17 +0300 Subject: [PATCH] Show dark version of site when prefers-color-scheme:dark (#8921) --- js/docs.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/js/docs.js b/js/docs.js index db4297152b..46102a04e1 100644 --- a/js/docs.js +++ b/js/docs.js @@ -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); } });