diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-04-17 22:42:59 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-04-17 22:42:59 +0800 |
commit | 8cf7e9d524db6c7bbb88327d1376a9455f74152f (patch) | |
tree | 1c10378740184c2a06b895f2eea71b5fdaa1aca3 | |
parent | 3153fc3f10a6c5b2a9989d09b6fa6587b353dd83 (diff) |
Press enter to pick first candidate
-rw-r--r-- | index.css | 4 | ||||
-rw-r--r-- | index.js | 9 |
2 files changed, 12 insertions, 1 deletions
@@ -51,6 +51,10 @@ h1 { cursor: pointer; } +.candidate:first-child { + font-weight: bold; +} + .album-cover { width: 50px; } @@ -111,8 +111,14 @@ inputElem.oninput = () => { } } +inputElem.onkeyup = (event) => { + if (event.key == "Enter") { + pickSong(); // no arguments passed, pick first option + } +} + function pickSong(event) { - const candidate = event.currentTarget; + const candidate = event ? event.currentTarget : candidateListElem.firstChild; const trackTitleElem = candidate.querySelector("span"); if (trackTitleElem.innerText === currentWord.track) { // the guess is correct @@ -122,6 +128,7 @@ function pickSong(event) { elem.disabled = true; } showAnswer(); + nextElem.focus(); } else { if (!hintTaken) { reportElem.innerHTML = "Sorry, not this song :) <br /> Try a hint?"; |