]> git.ardis.lu - ardislu.dev/commitdiff
Enable pressing spacebar to click links
authorArdis Lu <ardisglu@gmail.com>
Mon, 28 Oct 2024 04:27:31 +0000 (21:27 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 28 Oct 2024 04:27:31 +0000 (21:27 -0700)
script.js

index 6cda4742dd993961a3aac2f8c458e7087cb856aa..9a51f6d3eb8115f2e25a3ef7554e9d8ff793ac43 100644 (file)
--- a/script.js
+++ b/script.js
@@ -394,6 +394,14 @@ document.addEventListener('click', e => {
   }
 });
 
+/* Enable pressing spacebar to click <a> links. */
+document.addEventListener('keydown', e => {
+  if (e.code === 'Space' && e.target?.tagName === 'A') {
+    e.preventDefault();
+    e.target.click();
+  }
+});
+
 /* DevTools console help message. */
 const ascii =
 `┌──────────────────────────────────────────────────────────┐
This page took 0.039771 seconds and 4 git commands to generate.