interface Params { s?: string, } let params: Params = Object.fromEntries( new URLSearchParams(location.hash.substr(1)) .entries()); function setParams() { let formatter = new URLSearchParams; if (params.s) { formatter.set("s", params.s); } history.replaceState( null, document.title, `#${formatter}`); } export function getGame(): string | undefined { return params.s; } export function setGame(g: string): void { params.s = g; setParams(); }