Skip to content

Commit

Permalink
Added Space key to chatgpt.alert() dismissers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Jun 23, 2024
1 parent 51bf6cb commit 8f3b1b7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,15 @@ const chatgpt = { // eslint-disable-line no-redeclare
const clickHandler = event => { // explicitly defined to support removal post-dismissal
if (event.target == event.currentTarget || event.target instanceof SVGPathElement) dismissAlert(); };
const keyHandler = event => { // to dismiss active alert
const dismissKeys = ['Enter', 'Return', 'Escape', 'Esc'], dismissKeyCodes = [13, 27];
const dismissKeys = [' ', 'Spacebar', 'Enter', 'Return', 'Escape', 'Esc'],
dismissKeyCodes = [32, 13, 27];
if (dismissKeys.includes(event.key) || dismissKeyCodes.includes(event.keyCode)) {
for (const alertId of alertQueue) { // look to handle only if triggering alert is active
const alert = document.getElementById(alertId);
if (alert && alert.style.display !== 'none') { // active alert found
if (event.key.includes('Esc') || event.keyCode == 27) // if esc pressed
if (event.key.includes('Esc') || event.keyCode == 27) // esc pressed
dismissAlert(); // dismiss alert & do nothing
else if (['Enter', 'Return'].includes(event.key) || event.keyCode == 13) { // else if enter pressed
else if ([' ', 'Spacebar', 'Enter', 'Return'].includes(event.key) || [32, 13].includes(event.keyCode)) { // space/enter pressed
const mainButton = alert.querySelector('.modal-buttons').lastChild; // look for main button
if (mainButton) { mainButton.click(); event.preventDefault(); } // click if found
} return;
Expand Down

0 comments on commit 8f3b1b7

Please sign in to comment.