X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/48fd211cd255ea9ff05d0556eed4b6033683794a..ac13b92b26d4fa871749fa22be8d8f41f5b9641d:/lib/functions.js.php?ds=sidebyside diff --git a/lib/functions.js.php b/lib/functions.js.php index c1a81d8..1114dfd 100644 --- a/lib/functions.js.php +++ b/lib/functions.js.php @@ -789,4 +789,34 @@ function addCopyListener(button_id, link_id) { copyLinkToClipboard(link_id);}); } } + +function set_dark_mode() { + let steel_sheet = ""; + let shortcut_icon = ""; + document.getElementById('stylesheet').href = steel_sheet; + document.getElementById('shortcut_icon').href = steel_sheet; +} + +function set_light_mode() { + let steel_sheet = ""; + let shortcut_icon = ""; + document.getElementById('stylesheet').href = steel_sheet; + document.getElementById('shortcut_icon').href = steel_sheet; +} + +function color_scheme_preferences() { + + let dark_mode_steel_sheet = "" + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + set_dark_mode(); + } else { + set_light_mode(); + } + + // When user change its preference + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', lightMode => { + lightMode.matches ? set_dark_mode() : set_light_mode(); + }); +} + // @license-end