mirror of
https://github.com/Alamantus/Lexiconga.git
synced 2025-05-24 02:51:14 +02:00
29 lines
No EOL
849 B
JavaScript
29 lines
No EOL
849 B
JavaScript
// https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie/4825695#4825695
|
|
|
|
export function setCookie (name, value, days) {
|
|
let expires;
|
|
if (days) {
|
|
const date = new Date();
|
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
expires = '; expires=' + date.toGMTString();
|
|
}
|
|
else {
|
|
expires = '';
|
|
}
|
|
document.cookie = name + '=' + value + expires + '; path=/';
|
|
}
|
|
|
|
export function getCookie(c_name) {
|
|
if (document.cookie.length > 0) {
|
|
let c_start = document.cookie.indexOf(c_name + '=');
|
|
if (c_start != -1) {
|
|
c_start = c_start + c_name.length + 1;
|
|
let c_end = document.cookie.indexOf(';', c_start);
|
|
if (c_end == -1) {
|
|
c_end = document.cookie.length;
|
|
}
|
|
return unescape(document.cookie.substring(c_start, c_end));
|
|
}
|
|
}
|
|
return '';
|
|
} |