/** Client-only favorite quest pin (one active quest at a time). */ const STORAGE_KEY = "questward-favorite-quest"; /** * @returns {Record} */ function readMap () { try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) { return {}; } const parsed = JSON.parse(raw); if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) { return {}; } /** @type {Record} */ const out = {}; for (const [key, value] of Object.entries(parsed)) { if (typeof value === "string" && value.trim()) { out[String(key)] = value.trim(); } } return out; } catch { return {}; } } function writeMap (map) { try { localStorage.setItem(STORAGE_KEY, JSON.stringify(map)); } catch { /* ignore quota / private mode */ } } export function loadFavoriteQuestId (characterId) { const id = characterId | 0; if (!id) { return null; } return readMap()[String(id)] ?? null; } export function saveFavoriteQuestId (characterId, questId) { const id = characterId | 0; if (!id) { return; } const map = readMap(); const next = String(questId ?? "").trim(); if (!next) { delete map[String(id)]; } else { map[String(id)] = next; } writeMap(map); } export function clearFavoriteQuestId (characterId) { saveFavoriteQuestId(characterId, null); }