Skip to content

Commit

Permalink
Updated the cookie file
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowWolf308 committed Jul 17, 2023
1 parent af1bc9b commit a4b476d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/js/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
const cookies = ["colors", "maxScore", "coinAmount"];

cookies.forEach((cookieName) => {
document.cookie = document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/Flappy-Bird";
cookies.forEach(function(cookie) {
deleteCookieFromOldPath(cookie);
});

/*
Expand Down Expand Up @@ -43,6 +43,11 @@ function setCookie(cookieValue, cookieName = "", daysUntillExpire = 1000) {
document.cookie = cookie;
}

// function to delete a cookie from the old path
function deleteCookieFromOldPath(cookieName = "") {
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/Flappy-Bird";
}

// This still needs to be used somewhere but for now it is unused code
function deleteCookie(cookieName = "") {
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/";
Expand Down Expand Up @@ -144,11 +149,14 @@ function checkColors(cookieValue) {
if (array.includes(cookieValue)) {
return;
}

array.push(cookieValue);
let valueForCookie = array.toString();

if (valueForCookie.substring(0, 1) === ",") {
valueForCookie = valueForCookie.slice(1);
}

setCookie(valueForCookie, cookieName);
return;
}
Expand Down

0 comments on commit a4b476d

Please sign in to comment.