diff options
| author | Sivaldo <sivaldodavi@disroot.org> | 2026-06-13 19:20:23 -0300 |
|---|---|---|
| committer | Sivaldo <sivaldodavi@disroot.org> | 2026-06-13 19:20:23 -0300 |
| commit | 7316238f16655bd127b04476bbf7864b27f940f9 (patch) | |
| tree | 61f25290b3e5fd14894e52754cfe6dd4e85845ef /static/keyboard-shortcuts.js | |
Diffstat (limited to 'static/keyboard-shortcuts.js')
| -rw-r--r-- | static/keyboard-shortcuts.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/static/keyboard-shortcuts.js b/static/keyboard-shortcuts.js new file mode 100644 index 0000000..53cfe44 --- /dev/null +++ b/static/keyboard-shortcuts.js @@ -0,0 +1,73 @@ +/** + * Keyboard Shortcuts + * Atalhos para acelerar a navegação e resposta de quizzes + * + * Atalhos: + * 1-5: Selecionar opção A-E + * Espaço: Próxima questão + * Esc: Fechar notas/floaters + * ?: Mostrar ajuda + */ + +const SHORTCUTS = { + '1': () => selectOptionByLetter(0), + '2': () => selectOptionByLetter(1), + '3': () => selectOptionByLetter(2), + '4': () => selectOptionByLetter(3), + '5': () => selectOptionByLetter(4), + ' ': (e) => { + e.preventDefault(); + const nextBtn = document.getElementById('btn-next'); + if (nextBtn && nextBtn.style.display !== 'none') { + nextBtn.click(); + } + }, + 'Escape': () => { + // Fechar floaters se existir + if (typeof closeFloater === 'function') { + closeFloater(); + } + }, + '?': (e) => { + e.preventDefault(); + showKeyboardHelp(); + }, +}; + +function selectOptionByLetter(index) { + const buttons = document.querySelectorAll('.opt'); + if (buttons[index]) { + buttons[index].click(); + } +} + +function showKeyboardHelp() { + const help = ` +⌨️ Atalhos de Teclado + +Quizzes: + 1-5 Selecionar opção A-E + SPC Próxima questão + ESC Fechar notas + +Geral: + ESC Fechar floaters + ? Mostrar esta ajuda + `; + + alert(help); +} + +document.addEventListener('keydown', (e) => { + // Ignorar se está digitando em um input/textarea + if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') { + return; + } + + const key = e.key; + const handler = SHORTCUTS[key]; + + if (handler) { + handler(e); + } +}); |
