hugo-theme-noteworthy/static/js/main.js
2024-11-29 18:10:22 +01:00

59 lines
1.4 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function() {
setDarkMode()
var coll = document.getElementsByClassName("collapsible")
for (let i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active")
var content = this.nextElementSibling
if (content.style.display === "block") {
content.style.display = "none"
} else {
content.style.display = "block"
}
})
}
})
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")
}