diff --git a/src/main.js b/src/main.js index 19cfd75..1b8a1f8 100644 --- a/src/main.js +++ b/src/main.js @@ -21,6 +21,7 @@ for (const [displayName, automaton] of Object.entries(AUTOMATONS)) { const handleEvent = () => { automatonSelector.setAttribute('hidden', 'hidden'); app.removeAttribute('hidden'); + history.replaceState({ automaton }, '', `#${encodeURIComponent(displayName)}`); openAutomaton(trUserContent(displayName), automaton); }; card.addEventListener('click', handleEvent); @@ -46,7 +47,15 @@ create.addEventListener('click', () => { openAutomaton('', [], true); }); +const hash = decodeURIComponent(location.hash.slice(1)); +if (AUTOMATONS.hasOwnProperty(hash)) { + openAutomaton(trUserContent(hash), AUTOMATONS[/** @type {keyof typeof AUTOMATONS} */ (hash)]); + automatonSelector.setAttribute('hidden', 'hidden'); + app.removeAttribute('hidden'); +} + backButton.addEventListener('click', () => { app.setAttribute('hidden', 'hidden'); automatonSelector.removeAttribute('hidden'); + history.replaceState({}, '', '#'); });