25 lines
775 B
JavaScript
25 lines
775 B
JavaScript
// Path: Loader/scripts/storage.js
|
|
|
|
import { LOADER_INTENT_STORAGE_KEY, LOADER_META_STORAGE_KEY, LOADER_SEEN_COOKIE_MAX_AGE_SECONDS, LOADER_SEEN_COOKIE_NAME } from "./config.js";
|
|
import { collectClientHints } from "./hints.js";
|
|
|
|
export const persistLoaderState = (intent) => {
|
|
const payload = {
|
|
intent,
|
|
hints: collectClientHints(),
|
|
};
|
|
|
|
try {
|
|
window.sessionStorage.setItem(LOADER_INTENT_STORAGE_KEY, intent);
|
|
window.sessionStorage.setItem(LOADER_META_STORAGE_KEY, JSON.stringify(payload));
|
|
} catch (error) {
|
|
console.warn("[Loader] Unable to persist bootstrap state.", error);
|
|
}
|
|
|
|
return payload;
|
|
};
|
|
|
|
export const markLoaderSeen = () => {
|
|
document.cookie = `${LOADER_SEEN_COOKIE_NAME}=1; Path=/; Max-Age=${LOADER_SEEN_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;
|
|
};
|