57e8668aa9f78c5209840e4454c85905662a604b
1 // Source: https://www.quirksmode.org/js/cookies.html
2 export function setCookie(name
, value
) {
3 const date
= new Date();
4 date
.setTime(date
.getTime() + 183 * 24 * 60 * 60 * 1000); //6 months
5 const expires
= "; expires=" + date
.toGMTString();
6 document
.cookie
= name
+ "=" + value
+ expires
+ "; path=/;";
9 export function getCookie(name
, defaut
) {
10 const nameEQ
= name
+ "=";
11 const ca
= document
.cookie
.split(";");
12 for (let i
= 0; i
< ca
.length
; i
++) {
14 while (c
.charAt(0) == " ") c
= c
.substring(1, c
.length
);
15 if (c
.indexOf(nameEQ
) == 0) return c
.substring(nameEQ
.length
, c
.length
);
17 return defaut
; //cookie not found
20 export function delCookie(name
) {
21 document
.cookie
= name
+ "=; Max-Age=-1;";