feat(favs): Sterne-Favoriten pro Sound; Speicherung per Cookie (ohne Login)
This commit is contained in:
parent
f619cac653
commit
99588e446c
3 changed files with 70 additions and 6 deletions
18
web/src/cookies.ts
Normal file
18
web/src/cookies.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export function setCookie(name: string, value: string, days = 365): void {
|
||||
const expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
|
||||
document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; expires=${expires}; path=/; SameSite=Lax`;
|
||||
}
|
||||
|
||||
export function getCookie(name: string): string | null {
|
||||
const key = `${encodeURIComponent(name)}=`;
|
||||
const parts = document.cookie.split(';');
|
||||
for (const part of parts) {
|
||||
const trimmed = part.trim();
|
||||
if (trimmed.startsWith(key)) {
|
||||
return decodeURIComponent(trimmed.slice(key.length));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue