From bafd0b747449e0d1814389ddc3d528e0ca8b6ed2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 12 Dec 2019 20:35:12 +0300 Subject: enable automatic night mode for index pages --- js/common.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'js') diff --git a/js/common.js b/js/common.js index b42491d..ecc8206 100644 --- a/js/common.js +++ b/js/common.js @@ -32,4 +32,21 @@ function offline_remove(id, callback) { } } +function init_night_mode() { + if (window.matchMedia) { + const mql = window.matchMedia('(prefers-color-scheme: dark)'); + mql.addEventListener("change", () => { + apply_night_mode(mql.matches); + }); + + apply_night_mode(mql.matches); + } +} + +function apply_night_mode(is_night) { + console.log("night mode changed to", is_night); + + $("#theme_css").attr("href", + "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css")); +} -- cgit v1.2.3