blob: 44992a26a0db3b5346d8d8ae45a7f142641b113f (
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
37
38
|
'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()});
}
}
window.Cookies = Cookies;
|