Spaces:
Running
Running
File size: 942 Bytes
16ff49b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | // Played-case memory: ids of every case this browser has STARTED, oldest first.
// Sent with New Case so the server never deals this player a mystery they've seen.
const KEY = 'cz-played'
const CAP = 200
interface Stored {
v: 1
ids: string[]
}
export function getPlayed(): string[] {
try {
const raw = localStorage.getItem(KEY)
if (!raw) return []
const data = JSON.parse(raw) as Stored
if (data?.v !== 1 || !Array.isArray(data.ids)) return []
return data.ids.filter((x) => typeof x === 'string')
} catch {
return []
}
}
export function markPlayed(id: string): void {
if (!id) return
try {
const ids = getPlayed().filter((x) => x !== id)
ids.push(id) // most recent last; the server uses order for its repeat-of-last-resort
localStorage.setItem(KEY, JSON.stringify({ v: 1, ids: ids.slice(-CAP) }))
} catch {
/* private mode etc. — repeats become possible, nothing breaks */
}
}
|