fix: preserve Unicode floor state in viewer URLs
Some checks failed
ci / test (macos-latest, 3.10) (push) Has been cancelled
ci / test (macos-latest, 3.12) (push) Has been cancelled
ci / test (ubuntu-latest, 3.10) (push) Has been cancelled
ci / test (ubuntu-latest, 3.12) (push) Has been cancelled
ci / test (windows-latest, 3.10) (push) Has been cancelled
ci / test (windows-latest, 3.12) (push) Has been cancelled
ci / browser-smoke (push) Has been cancelled
Some checks failed
ci / test (macos-latest, 3.10) (push) Has been cancelled
ci / test (macos-latest, 3.12) (push) Has been cancelled
ci / test (ubuntu-latest, 3.10) (push) Has been cancelled
ci / test (ubuntu-latest, 3.12) (push) Has been cancelled
ci / test (windows-latest, 3.10) (push) Has been cancelled
ci / test (windows-latest, 3.12) (push) Has been cancelled
ci / browser-smoke (push) Has been cancelled
This commit is contained in:
@@ -855,6 +855,21 @@ function renderBookmarkList() {
|
||||
}
|
||||
|
||||
// ───────────────────────── URL Hash State ─────────────────────────
|
||||
function encodeHashState(value) {
|
||||
const bytes = new TextEncoder().encode(value);
|
||||
let binary = "";
|
||||
for (let index = 0; index < bytes.length; index += 0x8000) {
|
||||
binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
|
||||
}
|
||||
return btoa(binary).replace(/=/g, "");
|
||||
}
|
||||
|
||||
function decodeHashState(value) {
|
||||
const padded = value + "=".repeat((4 - (value.length % 4)) % 4);
|
||||
const binary = atob(padded);
|
||||
return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
|
||||
}
|
||||
|
||||
function serializeStateToHash() {
|
||||
const hash = {
|
||||
f: Object.entries(state.floors).filter(([, v]) => !v).map(([k]) => k), // only store disabled
|
||||
@@ -867,7 +882,7 @@ function serializeStateToHash() {
|
||||
},
|
||||
b: bookmarks,
|
||||
};
|
||||
const encoded = btoa(JSON.stringify(hash)).replace(/=/g, "");
|
||||
const encoded = encodeHashState(JSON.stringify(hash));
|
||||
history.replaceState(null, "", `#${encoded}`);
|
||||
}
|
||||
|
||||
@@ -875,7 +890,7 @@ function restoreStateFromHash() {
|
||||
try {
|
||||
const raw = window.location.hash.slice(1);
|
||||
if (!raw) return;
|
||||
const hash = JSON.parse(atob(raw));
|
||||
const hash = JSON.parse(decodeHashState(raw));
|
||||
if (hash.f) for (const fk of hash.f) { if (fk in state.floors) state.floors[fk] = false; }
|
||||
if (hash.c) for (const ck of hash.c) { if (ck in state.categories) state.categories[ck] = false; }
|
||||
if (hash.s) { sectionInput.value = hash.s; applySection(Number(hash.s)); }
|
||||
|
||||
Reference in New Issue
Block a user