diff options
author | pacien | 2024-01-05 02:24:14 +0100 |
---|---|---|
committer | pacien | 2024-01-05 02:24:14 +0100 |
commit | 95cbf08f037cf2ef63262d96e9ab4cc473529329 (patch) | |
tree | 59fd440e60852485d47516f5337aa53da1b1fc05 /app.js | |
parent | c74633af67e28a339c71cb015e031eb543f4307c (diff) | |
download | echoclip-95cbf08f037cf2ef63262d96e9ab4cc473529329.tar.gz |
implement keyboard shortcut to quick replay clips
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -15,6 +15,22 @@ clearBtn.addEventListener("click", _event => { | |||
15 | clips.textContent = ""; | 15 | clips.textContent = ""; |
16 | }); | 16 | }); |
17 | 17 | ||
18 | function onNthClip(index, action) { | ||
19 | if (index < 0 || clips.children.length <= index - 1) return; | ||
20 | const clip = clips.children[index - 1].querySelector("audio"); | ||
21 | action(clip); | ||
22 | } | ||
23 | |||
24 | document.addEventListener("keydown", event => { | ||
25 | if (event.key.match(/[1-9]/)) | ||
26 | onNthClip(parseInt(event.key), clip => clip.play()); | ||
27 | }); | ||
28 | |||
29 | document.addEventListener("keyup", event => { | ||
30 | if (event.key.match(/[1-9]/)) | ||
31 | onNthClip(parseInt(event.key), clip => stopPlayer(clip)); | ||
32 | }); | ||
33 | |||
18 | function stopPlayer(player) { | 34 | function stopPlayer(player) { |
19 | player.pause(); | 35 | player.pause(); |
20 | player.currentTime = 0; | 36 | player.currentTime = 0; |
@@ -66,7 +82,6 @@ function onGetDeviceSuccess(stream) { | |||
66 | 82 | ||
67 | // TODO: record blob and list to local persistent storage | 83 | // TODO: record blob and list to local persistent storage |
68 | // TODO: buttons to clear individual clips | 84 | // TODO: buttons to clear individual clips |
69 | // TODO: keyboard shortcut to play clips for the ten last indexes | ||
70 | 85 | ||
71 | clips.prepend(wrapElement("li", audioElement)); | 86 | clips.prepend(wrapElement("li", audioElement)); |
72 | 87 | ||