aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/getCookie.ts
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-08-30 20:58:25 +0200
committerstonedDiscord <Tukz@gmx.de>2022-08-30 20:58:25 +0200
commit325aa41d1216facbb7228743930a8ad21afec7aa (patch)
tree63e454a9f7876f4839abad79482e2171aac04df4 /webAO/utils/getCookie.ts
parent2838fbe91a270ed3d69ac708dac85b108b6f09dc (diff)
convert cookie stuff to ts
Diffstat (limited to 'webAO/utils/getCookie.ts')
-rw-r--r--webAO/utils/getCookie.ts26
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;