From 01071eb1502630962b2ada9b7366639585618708 Mon Sep 17 00:00:00 2001 From: ahaoboy <504595380@qq.com> Date: Sat, 1 Mar 2025 20:46:43 +0800 Subject: [PATCH] support hashchange --- src/analyze/index.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/analyze/index.ts b/src/analyze/index.ts index 12d6ebe..785859e 100644 --- a/src/analyze/index.ts +++ b/src/analyze/index.ts @@ -110,16 +110,22 @@ document.getElementById('loadExample')!.onclick = () => { fetch('example-metafile.json').then(r => r.text()).then(finishLoading) } -if (location.hash !== '') { - // Load from the hash if it's present - try { - finishLoading(atob(location.hash.slice(1))) - } catch (e) { - } +function loadHash(){ + if (location.hash !== '') { + // Load from the hash if it's present + try { + finishLoading(atob(location.hash.slice(1))) + } catch (e) { + } - // Clear out the hash afterward - try { - history.replaceState({}, '', location.pathname) - } catch (e) { + // Clear out the hash afterward + try { + history.replaceState({}, '', location.pathname) + } catch (e) { + } } } + +window.addEventListener('hashchange', loadHash); + +loadHash()