From ecbf7f0f8a775369dff4842f703e45ffd63cd96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A2=D1=80=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Fri, 24 Jul 2026 08:30:08 +0300 Subject: [PATCH] history population to handle back events --- app.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app.js b/app.js index 1e10c0e..75871ac 100644 --- a/app.js +++ b/app.js @@ -221,9 +221,15 @@ let game = { mistakes: [], }; +let popstateHandled = false; + function showScreen(id) { document.querySelectorAll('.screen').forEach(s => s.classList.remove('active')); document.getElementById('screen-' + id).classList.add('active'); + if (id !== 'menu' && !popstateHandled) { + history.pushState({ screen: id }, ''); + } + popstateHandled = false; } function shuffle(arr) { @@ -978,3 +984,25 @@ document.addEventListener('keydown', (e) => { } } }); + +// Handle mobile back/cancel button +const BACK_MAP = { + 'screen-setup-system': 'btn-system-back', + 'screen-setup-range': 'btn-range-back', + 'screen-setup-options': 'btn-options-back', + 'screen-game': 'btn-stop', + 'screen-results': 'btn-results-menu', + 'screen-theory-system': 'btn-theory-back', + 'screen-theory-content': 'btn-theory-content-back', +}; + +window.addEventListener('popstate', () => { + const active = document.querySelector('.screen.active'); + if (!active) return; + + const btnId = BACK_MAP[active.id]; + if (btnId) { + popstateHandled = true; + document.getElementById(btnId).click(); + } +});