add darkmode cookie
This commit is contained in:
@@ -69,6 +69,7 @@
|
||||
$('.darkmode-text-dark').addClass('text-dark').removeClass('darkmode-text-dark');
|
||||
$('.darkmode-text-muted').addClass('text-muted').removeClass('darkmode-text-muted');
|
||||
};
|
||||
switchDarkmodeSetting();
|
||||
});
|
||||
if ($('input.custom-control-input').is(':checked')) {
|
||||
$("body").toggleClass("darkmode");
|
||||
@@ -78,6 +79,7 @@
|
||||
$("nav").toggleClass("navbar-light");
|
||||
$('.text-dark').addClass('darkmode-text-dark').removeClass('text-dark');
|
||||
$('.text-muted').addClass('darkmode-text-muted').removeClass('text-muted');
|
||||
switchDarkmodeSetting();
|
||||
};
|
||||
</script>
|
||||
{{- partial "sections/v3/auto_darkmode.html" . -}}
|
||||
|
||||
@@ -152,6 +152,7 @@
|
||||
.addClass("text-muted")
|
||||
.removeClass("darkmode-text-muted");
|
||||
}
|
||||
switchDarkmodeSetting();
|
||||
});
|
||||
if ($("input.custom-control-input").is(":checked")) {
|
||||
$("body").toggleClass("darkmode");
|
||||
@@ -166,6 +167,7 @@
|
||||
$(".about-backdark").toggleClass("about-back");
|
||||
$(".education-backdark").toggleClass("education-back");
|
||||
$(".achievements-backdark").toggleClass("achievements-back");
|
||||
switchDarkmodeSetting();
|
||||
}
|
||||
</script>
|
||||
{{- partial "sections/v3/auto_darkmode.html" . -}}
|
||||
|
||||
@@ -1,4 +1,59 @@
|
||||
let darkmode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
if (darkmode) {
|
||||
function setCookie(cname, cvalue) {
|
||||
document.cookie = cname + "=" + cvalue + ";path=/;";
|
||||
}
|
||||
|
||||
function getCookie(cname) {
|
||||
let name = cname + "=";
|
||||
let decodedCookie = decodeURIComponent(document.cookie);
|
||||
let ca = decodedCookie.split(';');
|
||||
for(let i = 0; i <ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function getDarkmodeSetting() {
|
||||
switch(getCookie("darkmode")) {
|
||||
case "true":
|
||||
return true;
|
||||
case "false":
|
||||
return false;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function setDarkmodeSetting(value) {
|
||||
if (value) {
|
||||
setCookie("darkmode", "true");
|
||||
} else {
|
||||
setCookie("darkmode", "false");
|
||||
}
|
||||
}
|
||||
|
||||
function switchDarkmodeSetting() {
|
||||
let darkmode = getDarkmodeSetting();
|
||||
switch(darkmode) {
|
||||
case true:
|
||||
setDarkmodeSetting(false);
|
||||
break;
|
||||
case false:
|
||||
setDarkmodeSetting(true);
|
||||
break;
|
||||
default:
|
||||
setDarkmodeSetting(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let darkmode = getDarkmodeSetting();
|
||||
let darkmode_prefer = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
if ((darkmode_prefer && darkmode===null) || darkmode) {
|
||||
$(".darkmode-label").click();
|
||||
}
|
||||
Reference in New Issue
Block a user