From 09b952e80e4b4969a42146707f3a305ea204c222 Mon Sep 17 00:00:00 2001 From: Gerben Date: Tue, 5 Nov 2019 14:49:10 +0100 Subject: [PATCH] Capture every space press Otherwise spacebar does not work if focus is on the sound input or a bookmark link (in development). We will need to revise the approach if we make any text input fields. --- app/audio-player/contentscript.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/audio-player/contentscript.js b/app/audio-player/contentscript.js index 7e7aeb7..2a5cb36 100644 --- a/app/audio-player/contentscript.js +++ b/app/audio-player/contentscript.js @@ -40,11 +40,13 @@ export default async function init() { } document.body.addEventListener('keydown', event => { - if (event.target !== document.body) return; + // Pressing spacebar triggers play/pause. if (event.code === 'Space') { playpause(); + event.stopPropagation(); + event.preventDefault(); } - }); + }, { capture: true }); // Load the file await playlist.load([{