Define a hash url for each example automaton

This commit is contained in:
2024-05-16 20:53:10 +02:00
parent 5f780c751a
commit 2e33a9cda9

View File

@@ -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({}, '', '#');
});