summaryrefslogtreecommitdiff
path: root/scripts/cookie.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/cookie.js')
-rw-r--r--scripts/cookie.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/cookie.js b/scripts/cookie.js
new file mode 100644
index 0000000..9c88963
--- /dev/null
+++ b/scripts/cookie.js
@@ -0,0 +1,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()});
+ }
+}