blob: 44a0be985ce2e7ac353aff13e790486a4c0e191c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
'use strict';
class Cookies {
static getCookie(name){
let cookies = document.cookie.split(";");
for(let i in cookies) {
let cname = cookies[i].trim().split("=")[0];
if(cname == name){
return cookies[i].trim().slice(name.length + 1);
}
}
return "";
}
static setCookie(name, value, data = {SameSite: "Strict"}) {
let extra = "";
for(let key in data)
{
extra += "; " + key + "=" + data[key];
}
document.cookie = name + "=" + value + extra;
}
static setYearCookie(name, value) {
var date = new Date(Date.now());
date.setFullYear(date.getFullYear() + 1);
Cookies.setCookie(name, value, {SameSite: "Strict", expires: date.toUTCString()});
}
static removeCookie(name) {
var date = new Date(0);
Cookies.setCookie(name, "", {SameSite: "Strict", expires: date.toUTCString()});
}
}
|