summaryrefslogtreecommitdiff
path: root/webcards/scripts/cookie.js
diff options
context:
space:
mode:
authorKyle Gunger <corechg@gmail.com>2020-05-17 13:15:41 -0400
committerKyle Gunger <corechg@gmail.com>2020-05-17 13:15:41 -0400
commitb48f0adccb11619680a47cac5fa9c68f638bd489 (patch)
tree9e75612c21ae9944b354afa13e2e94834e020e9c /webcards/scripts/cookie.js
parentc9e2eee382df60bc7a058b56c804258848477d67 (diff)
[WebCards] Update from my local repos
Diffstat (limited to 'webcards/scripts/cookie.js')
-rw-r--r--webcards/scripts/cookie.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/webcards/scripts/cookie.js b/webcards/scripts/cookie.js
new file mode 100644
index 0000000..2eb5977
--- /dev/null
+++ b/webcards/scripts/cookie.js
@@ -0,0 +1,39 @@
+function CookieManager() {
+}
+
+CookieManager.prototype = {
+ getCookie: function(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 "";
+ },
+
+ setCookie: function(name, value, data={}) {
+ let extra = "";
+
+ for(let key in data)
+ {
+ extra += "; " + key + "=" + data[key];
+ }
+
+ document.cookie = name + "=" + value + extra;
+ },
+
+ setYearCookie: function(name, value) {
+ var date = new Date(Date.now());
+ date.setFullYear(date.getFullYear() + 1);
+ this.setCookie(name, value, {expires: date.toUTCString()});
+ },
+
+ removeCookie: function(name) {
+ var date = new Date(0);
+ this.setCookie(name, "", {expires: date.toUTCString()});
+ }
+};
+
+var Cookies = new CookieManager(); \ No newline at end of file