Improved shortcut handling

This commit is contained in:
gpkvt 2023-06-04 22:08:01 +02:00
parent 69a911e957
commit e80a9b89c9
1 changed files with 28 additions and 11 deletions

View File

@ -1,19 +1,32 @@
var checkedGroups = 0; var checkedGroups = [1,2,3,4,5];
var countdownActive = false;
function monitorRadio() { function monitorRadio() {
document.querySelectorAll('input[type="radio"]').forEach(function (el) { document.querySelectorAll('input[type="radio"]').forEach(function (el) {
el.addEventListener('change', incCounter, { once: true }); el.addEventListener('change', removeId, { once: true });
}); });
} }
function incCounter() { function removeId(e) {
checkedGroups++; if (e) {
value = e.target.id.charAt(1);
} else {
value = checkedGroups[0];
}
checkedGroups = checkedGroups.filter(function(item) {
return item != value;
})
} }
function checkCount() { function checkCount() {
if (checkedGroups === 5) { if (checkedGroups.length == 0) {
countdown(); if (countdownActive == false) {
countdown();
}
countdownActive = true;
return true;
} }
return false;
} }
window.addEventListener("keydown", function (event) { window.addEventListener("keydown", function (event) {
@ -21,18 +34,22 @@ window.addEventListener("keydown", function (event) {
return; return;
} }
checkCount(); if (checkCount()) {
return;
};
switch (event.key) { switch (event.key) {
case "a": case "a":
checkedGroups++; value = checkedGroups[0];
getid = 'a'+checkedGroups; removeId();
getid = 'a'+value;
document.getElementById(getid).checked = true; document.getElementById(getid).checked = true;
checkCount(); checkCount();
break; break;
case "b": case "b":
checkedGroups++; value = checkedGroups[0];
getid = 'b'+checkedGroups; removeId();
getid = 'b'+value;
document.getElementById(getid).checked = true; document.getElementById(getid).checked = true;
checkCount(); checkCount();
break; break;