45 lines
1019 B
JavaScript
45 lines
1019 B
JavaScript
document.addEventListener("DOMContentLoaded", function() {
|
|
setDarkMode()
|
|
})
|
|
|
|
|
|
function setCookie(cname, cvalue, exdays) {
|
|
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 isStringTrue(val) {
|
|
return String(val).toLowerCase() === 'true'
|
|
}
|
|
|
|
function toggleDarkMode() {
|
|
let darkMode = getCookie("setDarkMode");
|
|
if(isStringTrue(darkMode))
|
|
setCookie("setDarkMode", false);
|
|
else
|
|
setCookie("setDarkMode", true);
|
|
document.body.classList.toggle("dark-mode");
|
|
}
|
|
|
|
|
|
function setDarkMode() {
|
|
let darkMode = getCookie("setDarkMode");
|
|
if(isStringTrue(darkMode))
|
|
document.body.classList.toggle("dark-mode");
|
|
}
|