mirror of
https://github.com/khairul169/honey.git
synced 2025-04-28 14:59:32 +07:00
dark_mode: save preferences to browser's local storage
This commit is contained in:
parent
6487fd2572
commit
deca31442a
19
js/main.js
19
js/main.js
@ -1,8 +1,22 @@
|
|||||||
|
var CONFIG = {
|
||||||
|
"dark_mode": false
|
||||||
|
}
|
||||||
|
|
||||||
|
function config(key, value) {
|
||||||
|
if (value !== undefined) {
|
||||||
|
localStorage.setItem(key, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
let val = localStorage.getItem(key);
|
||||||
|
if (val === null) val = CONFIG.dark_mode;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
function onload() {
|
function onload() {
|
||||||
for_all("back", (btn) => {
|
for_all("back", (btn) => {
|
||||||
btn.onclick = back;
|
btn.onclick = back;
|
||||||
});
|
});
|
||||||
switch_theme(true);
|
switch_theme(config("dark_mode") == "true");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
back();
|
back();
|
||||||
document.body.classList.remove("init");
|
document.body.classList.remove("init");
|
||||||
@ -22,11 +36,12 @@ function back() {
|
|||||||
get_background().classList.add("scaled");
|
get_background().classList.add("scaled");
|
||||||
}
|
}
|
||||||
|
|
||||||
var is_dark = false;
|
|
||||||
function switch_theme(value) {
|
function switch_theme(value) {
|
||||||
back();
|
back();
|
||||||
|
let is_dark = config("dark_mode") == "true";
|
||||||
if (value === undefined) value = !is_dark;
|
if (value === undefined) value = !is_dark;
|
||||||
is_dark = value;
|
is_dark = value;
|
||||||
|
config("dark_mode", is_dark);
|
||||||
get("css_dark").disabled = !is_dark;
|
get("css_dark").disabled = !is_dark;
|
||||||
let bg_box = get("background").classList;
|
let bg_box = get("background").classList;
|
||||||
if (is_dark) {
|
if (is_dark) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user