Improve schemeSwap.js

This commit is contained in:
floppydiskette 2024-01-26 12:26:48 +00:00
parent fdeb7f1c48
commit bf5df323d2
Signed by: fwoppydwisk
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE

View file

@ -9,10 +9,10 @@ function getCookie(cname) {
let ca = decodedCookie.split(';'); let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) { for(let i = 0; i <ca.length; i++) {
let c = ca[i]; let c = ca[i];
while (c.charAt(0) == ' ') { while (c.charAt(0) === ' ') {
c = c.substring(1); c = c.substring(1);
} }
if (c.indexOf(name) == 0) { if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length); return c.substring(name.length, c.length);
} }
} }
@ -29,7 +29,7 @@ function setCookie(cname, cvalue, exdays) {
const d = new Date(); const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000)); d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString(); let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;SameSite=Strict";
} }
/** /**
@ -57,10 +57,10 @@ function setSchemeSelector() {
setCookie("colorscheme", "catppuccin-macchiato", 90); setCookie("colorscheme", "catppuccin-macchiato", 90);
} else { } else {
const scheme = getCookie("colorscheme"); const scheme = getCookie("colorscheme");
const schemeselector = document.getElementById("scheme-selector"); const scheme_selector = document.getElementById("scheme-selector");
if (scheme && schemeselector) { if (scheme && scheme_selector) {
for (let option of schemeselector.options) { for (let option of scheme_selector.options) {
if (option.value == scheme) { if (option.value === scheme) {
option.selected = true; option.selected = true;
break; break;
} }