feat: First iteration, multi themes, I18N
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// Thin wrapper over document.cookie. Values must already be cookie-safe
|
||||
// (see storage.js, which base64url-encodes everything).
|
||||
|
||||
const ONE_YEAR = 60 * 60 * 24 * 365;
|
||||
|
||||
export function readCookie(name) {
|
||||
const prefix = `${name}=`;
|
||||
for (const part of document.cookie.split('; ')) {
|
||||
if (part.startsWith(prefix)) return part.slice(prefix.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function writeCookie(name, value) {
|
||||
const secure = location.protocol === 'https:' ? '; Secure' : '';
|
||||
document.cookie = `${name}=${value}; Max-Age=${ONE_YEAR}; Path=/; SameSite=Lax${secure}`;
|
||||
}
|
||||
|
||||
export function removeCookie(name) {
|
||||
document.cookie = `${name}=; Max-Age=0; Path=/; SameSite=Lax`;
|
||||
}
|
||||
Reference in New Issue
Block a user