2024-03-06 21:38:09 +01:00
|
|
|
/**
|
|
|
|
* Return the content of a cookie with specified key
|
|
|
|
* @param key cookie name
|
|
|
|
*/
|
2024-03-08 11:23:32 +01:00
|
|
|
export function getCookie(key){
|
2024-03-06 21:38:09 +01:00
|
|
|
key = key + "="
|
|
|
|
let cookies = decodeURIComponent(document.cookie).split(";");
|
|
|
|
for (let el of cookies) {
|
|
|
|
el = el.trimStart();
|
|
|
|
if(el.indexOf(key) == 0){
|
|
|
|
return el.substr(key.length, el.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-03-08 11:23:32 +01:00
|
|
|
/**
|
|
|
|
* Return the content of a cookie with specified key
|
|
|
|
* @param key cookie name
|
|
|
|
*/
|
|
|
|
export function setCookie(key, value){
|
2024-03-08 22:00:15 +01:00
|
|
|
let cookie = key + "=" + value + "; SameSite=Lax";
|
2024-03-08 11:23:32 +01:00
|
|
|
document.cookie = cookie;
|
|
|
|
// Here we can apreciate the stupidity of Javascript :/
|
|
|
|
}
|