aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/resources/html/js-src/cookies.ts
diff options
context:
space:
mode:
Diffstat (limited to 'haddock-api/resources/html/js-src/cookies.ts')
-rw-r--r--haddock-api/resources/html/js-src/cookies.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/haddock-api/resources/html/js-src/cookies.ts b/haddock-api/resources/html/js-src/cookies.ts
new file mode 100644
index 00000000..3b68d6d8
--- /dev/null
+++ b/haddock-api/resources/html/js-src/cookies.ts
@@ -0,0 +1,20 @@
+export function setCookie(name: string, value: string) {
+ document.cookie = name + "=" + encodeURIComponent(value) + ";path=/;";
+}
+
+export function clearCookie(name: string) {
+ document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
+}
+
+export function getCookie(name: string) {
+ const nameEQ = name + "=";
+ const ca = document.cookie.split(';');
+ for (let i = 0; i < ca.length; i++) {
+ let c = ca[i];
+ while (c.charAt(0)==' ') c = c.substring(1,c.length);
+ if (c.indexOf(nameEQ) == 0) {
+ return decodeURIComponent(c.substring(nameEQ.length,c.length));
+ }
+ }
+ return null;
+} \ No newline at end of file