Skip to content

Commit

Permalink
fix #319: make shortcuts case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Oct 21, 2024
1 parent b0b3bb0 commit 63415b4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 76 deletions.
17 changes: 6 additions & 11 deletions client/geoword/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,14 @@ document.addEventListener('keydown', (event) => {
return;
}

switch (event.key) {
switch (event.key?.toLowerCase()) {
case ' ':
document.getElementById('buzz').click();
// Prevent spacebar from scrolling the page:
if (event.target === document.body) {
event.preventDefault();
}
break;
case 'n':
document.getElementById('next').click();
break;
case 's':
document.getElementById('start').click();
// Prevent spacebar from scrolling the page
if (event.target === document.body) { event.preventDefault(); }
break;

case 'n': return document.getElementById('next').click();
case 's': return document.getElementById('start').click();
}
});
32 changes: 9 additions & 23 deletions client/multiplayer/room.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ document.getElementById('year-range-a').onchange = function () {
socket.send(JSON.stringify({ type: 'set-year-range', minYear, maxYear }));
};

document.addEventListener('keydown', function (event) {
document.addEventListener('keydown', (event) => {
// press escape to close chat
if (event.key === 'Escape' && document.activeElement.id === 'chat-input') {
document.getElementById('chat-input').value = '';
Expand All @@ -961,38 +961,24 @@ document.addEventListener('keydown', function (event) {

if (['INPUT', 'TEXTAREA', 'SELECT'].includes(document.activeElement.tagName)) return;

switch (event.key) {
switch (event.key?.toLowerCase()) {
case ' ':
// Prevent spacebar from scrolling the page
document.getElementById('buzz').click();
if (event.target === document.body) event.preventDefault();
break;

case 'e':
document.getElementById('toggle-settings').click();
break;

case 'k':
document.getElementsByClassName('card-header-clickable')[0].click();
break;

case 't':
document.getElementsByClassName('star-tossup')[0].click();
// Prevent spacebar from scrolling the page
if (event.target === document.body) { event.preventDefault(); }
break;

case 'y':
navigator.clipboard.writeText(tossup._id ?? '');
break;
case 'e': return document.getElementById('toggle-settings').click();
case 'k': return document.getElementsByClassName('card-header-clickable')[0].click();
case 'p': return document.getElementById('pause').click();
case 't': return document.getElementsByClassName('star-tossup')[0].click();
case 'y': return navigator.clipboard.writeText(tossup._id ?? '');

case 'n':
case 's':
document.getElementById('next').click();
document.getElementById('skip').click();
break;

case 'p':
document.getElementById('pause').click();
break;
}
});

Expand Down
2 changes: 1 addition & 1 deletion client/multiplayer/room.min.js

Large diffs are not rendered by default.

47 changes: 13 additions & 34 deletions client/singleplayer/bonuses/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,45 +546,24 @@ document.getElementById('year-range-b').onchange = function () {
document.addEventListener('keydown', (event) => {
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(document.activeElement.tagName)) { return; }

switch (event.key) {
switch (event.key?.toLowerCase()) {
case ' ':
document.getElementById('reveal').click();
// Prevent spacebar from scrolling the page
if (event.target === document.body) { event.preventDefault(); }
break;
case 'e':
document.getElementById('toggle-settings').click();
break;
case 'k':
document.getElementsByClassName('card-header-clickable')[0].click();
break;
case 't':
document.getElementsByClassName('star-bonus')[0].click();
break;
case 'y':
navigator.clipboard.writeText(bonuses[0]?._id ?? '');
break;
case 'n':
document.getElementById('next').click();
break;
case 's':
document.getElementById('start').click();
break;
case '0':
document.getElementById(`checkbox-${currentBonusPart}`).click();
break;
case '1':
document.getElementById('checkbox-1').click();
break;
case '2':
document.getElementById('checkbox-2').click();
break;
case '3':
document.getElementById('checkbox-3').click();
break;
case '4':
document.getElementById('checkbox-4').click();
break;

case 'e': return document.getElementById('toggle-settings').click();
case 'k': return document.getElementsByClassName('card-header-clickable')[0].click();
case 'n': return document.getElementById('next').click();
case 's': return document.getElementById('start').click();
case 't': return document.getElementsByClassName('star-bonus')[0].click();
case 'y': return navigator.clipboard.writeText(bonuses[0]?._id ?? '');
case '0': return document.getElementById(`checkbox-${currentBonusPart}`).click();
case '1': return document.getElementById('checkbox-1').click();
case '2': return document.getElementById('checkbox-2').click();
case '3': return document.getElementById('checkbox-3').click();
case '4': return document.getElementById('checkbox-4').click();
}
});

Expand Down
Loading

0 comments on commit 63415b4

Please sign in to comment.