2023-02-21 17:11:28 +00:00
|
|
|
export function setCookie(name: string, value: string, expires: number) {
|
|
|
|
const d = new Date();
|
|
|
|
d.setTime(d.getTime() + expires);
|
|
|
|
const expires_at = "expires="+ d.toUTCString();
|
|
|
|
document.cookie = name + "=" + value + ";" + expires_at + ";path=/";
|
|
|
|
}
|
|
|
|
|
2023-02-21 18:42:27 +00:00
|
|
|
export function getCookie(name: string): string {
|
2023-02-21 17:11:28 +00:00
|
|
|
const name_with_equals = name + "=";
|
|
|
|
const decodedCookie = decodeURIComponent(document.cookie);
|
|
|
|
const 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_with_equals) == 0) {
|
|
|
|
return c.substring(name_with_equals.length, c.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|