summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-04-17 22:42:59 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-04-17 22:42:59 +0800
commit8cf7e9d524db6c7bbb88327d1376a9455f74152f (patch)
tree1c10378740184c2a06b895f2eea71b5fdaa1aca3
parent3153fc3f10a6c5b2a9989d09b6fa6587b353dd83 (diff)
Press enter to pick first candidate
-rw-r--r--index.css4
-rw-r--r--index.js9
2 files changed, 12 insertions, 1 deletions
diff --git a/index.css b/index.css
index e958e81..73883e9 100644
--- a/index.css
+++ b/index.css
@@ -51,6 +51,10 @@ h1 {
cursor: pointer;
}
+.candidate:first-child {
+ font-weight: bold;
+}
+
.album-cover {
width: 50px;
}
diff --git a/index.js b/index.js
index 06bf4c5..04b9868 100644
--- a/index.js
+++ b/index.js
@@ -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?";