21 lines
894 B
JavaScript
21 lines
894 B
JavaScript
function cookieBaker(key, value, expiry, path, secure, httpOnly, domain, sameSite) {
|
|
// Fuck secure parsing of the values real devs create cookies with unparsed values
|
|
document.cookie = `${key}=${value};${expiry ? `Expires=${expiry};` : ''} ${path ? `Path=${path};` : ''} Domain=${domain ? `${domain};` : ''} ${secure ? 'Secure;' : ''} ${httpOnly ? 'HttpOnly;' : ''} ${sameSite ? `SameSite=${sameSite};` : ''}`
|
|
}
|
|
|
|
function cookieEater(key) {
|
|
// https://www.w3schools.com/js/js_cookies.asp
|
|
let name = key + "=";
|
|
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 "";
|
|
} |