forked from hydralauncher/hydra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export function addCookieInterceptor() { | ||
Object.defineProperty(document, "cookie", { | ||
enumerable: true, | ||
configurable: true, | ||
get() { | ||
const cookies = localStorage.getItem("cookies") || ""; | ||
console.log("get cookie", cookies); | ||
return cookies; | ||
}, | ||
set(cookieString) { | ||
try { | ||
console.log("setting cookie", cookieString); | ||
const [cookieName, cookieValue] = cookieString.split(";")[0].split("="); | ||
|
||
const currentCookies = localStorage.getItem("cookies") || ""; | ||
|
||
console.log("pre cookies obj", currentCookies); | ||
const cookiesObject = parseCookieStringsToObjects(currentCookies); | ||
cookiesObject[cookieName] = cookieValue; | ||
console.log("cookiesObject", cookiesObject); | ||
|
||
const newString = Object.entries(cookiesObject) | ||
.map(([key, value]) => { | ||
return key + "=" + value; | ||
}) | ||
.join("; "); | ||
|
||
console.log("set cookie", newString); | ||
localStorage.setItem("cookies", newString); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
const parseCookieStringsToObjects = ( | ||
cookieStrings: string | ||
): { [key: string]: string } => { | ||
const result = {}; | ||
|
||
if (cookieStrings === "") return result; | ||
|
||
console.log(cookieStrings); | ||
cookieStrings.split(";").forEach((cookieString) => { | ||
console.log("forEach", cookieString); | ||
const [name, value] = cookieString.split("="); | ||
result[name.trim()] = value.trim(); | ||
}); | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters