From 8151b3eda4c77571bbe5df31eafab62b2a18873d Mon Sep 17 00:00:00 2001 From: Maximilian Bethke Date: Mon, 1 Feb 2021 15:21:25 +0100 Subject: [PATCH] Delete cookie.js (again) --- js/cookie.js | 82 ---------------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 js/cookie.js diff --git a/js/cookie.js b/js/cookie.js deleted file mode 100644 index d8b6657..0000000 --- a/js/cookie.js +++ /dev/null @@ -1,82 +0,0 @@ -class Cookie { - constructor(name) { - this.name = name; - this.value; - - // read the cookies value (initializes value) - this.get(); - } - - get() { - var allCookies = document.cookie; - var cookie; - - // find out how much cookies are set to be able to pick the right one - if(!allCookies) - { - // the tray is empty. leave fields as initialized - return; - } - - if(allCookies.indexOf(";") > 0) - { - // many cookies found, pick one - cookie = this.pickCookie(allCookies); - } else { - // only one cookie found. Check if its the right one - if(this.validateCookie(allCookies)) - { - cookie = allCookies; - } - } - - // read contents of the picked cookie - if(cookie) { - this.value = this.readCookieContents(cookie); - } else { - console.log("Coudn't get cookie"); - } - } - - pickCookie(manyCookies) { - manyCookies.split(";").forEach((cookie, _) => { - if(this.validateCookie(cookie)) - { - return cookie; - } - }); - } - - validateCookie(cookie) { - if(cookie.indexOf("=") >= 0) - { - var cookieCredentials = cookie.split("="); - var name = cookieCredentials[0] - return name == this.name; - } else { - return false; - } - } - - readCookieContents(cookie) { - var cookieCredentials = cookie.split("="); - var value = cookieCredentials[1]; - return JSON.parse(value); - } - - setValue(valueToBeSet) { - // update internal record - this.value = valueToBeSet; - - // prepare value for storing - var valueJSON = JSON.stringify(valueToBeSet); - - // set cookie with expiry on browser close - document.cookie = this.name+"="+valueJSON; - } - - getValue() { - this.get(); - return this.value; - } -} \ No newline at end of file