diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-10-12 18:25:14 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2022-10-12 18:25:14 +0200 |
| commit | 8a7942c0565298c29edbf0b271d5d7c7f9e56fd8 (patch) | |
| tree | 67b788f40b7a4713904836de05f0e5876c32bd79 /webAO/utils/getCookie.ts | |
| parent | a83c8962b68f2cc0a0e22d988b8ff030057454e5 (diff) | |
| parent | 82983e0c38383ec2602b4f41327342d1c8d0a8fd (diff) | |
Merge branch 'master' into 2fa
Diffstat (limited to 'webAO/utils/getCookie.ts')
| -rw-r--r-- | webAO/utils/getCookie.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/webAO/utils/getCookie.ts b/webAO/utils/getCookie.ts new file mode 100644 index 0000000..f5b9679 --- /dev/null +++ b/webAO/utils/getCookie.ts @@ -0,0 +1,26 @@ +/** + * read a cookie from storage + * got this from w3schools + * https://www.w3schools.com/js/js_cookies.asp + * @param {String} cname The name of the cookie to return + */ +const getCookie = (cname: String) => { + try { + const name = `${cname}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) === ' ') { + c = c.substring(1); + } + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length); + } + } + return ''; + } catch (error) { + return ''; + } +}; +export default getCookie; |
