diff --git a/templates/reader.html b/templates/reader.html index c012edc..ff57539 100644 --- a/templates/reader.html +++ b/templates/reader.html @@ -149,6 +149,27 @@ console.log("Could not find index for", filename); } } + + // Keyboard navigation: arrow keys for previous/next chapter + document.addEventListener('keydown', function(e) { + // Only handle arrow keys when not typing in an input/textarea + const isTyping = e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable; + if (isTyping) return; + + {% if prev_idx is not none %} + if (e.key === 'ArrowLeft') { + e.preventDefault(); + window.location.href = "/read/{{ book_id }}/{{ prev_idx }}"; + } + {% endif %} + + {% if next_idx is not none %} + if (e.key === 'ArrowRight') { + e.preventDefault(); + window.location.href = "/read/{{ book_id }}/{{ next_idx }}"; + } + {% endif %} + });