Skip to content

Commit

Permalink
Save Lighting Theme to Cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
athuler committed Feb 15, 2024
1 parent db4c334 commit 1b20a63
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,31 @@ function gtag(){dataLayer.push(arguments);}

<!-- Universal Scripts -->
<script>
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 "";
}
document.documentElement.setAttribute('data-bs-theme', getCookie("theme"));

document.getElementById('darkModeSwitch').addEventListener('click',()=>{
if (document.documentElement.getAttribute('data-bs-theme') == 'dark') {
document.documentElement.setAttribute('data-bs-theme','light')
document.documentElement.setAttribute('data-bs-theme','light');
document.cookie = "theme=light";
}
else {
document.documentElement.setAttribute('data-bs-theme','dark')
document.documentElement.setAttribute('data-bs-theme','dark');
document.cookie = "theme=dark";
}
})
</script>
Expand Down

0 comments on commit 1b20a63

Please sign in to comment.