From 94c30fef65a1beb49e65860c7ed99964e9c162e2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 20 Jul 2022 03:49:28 +0200 Subject: Attach key event listener to `` instead of `` Recently I noticed that sometimes the shortcut didn't work. The CSS classes and HTML structure didn't change. The shortcut stopped working after a navigation action. Maybe Turbolinks replaces `` now? Regardless, attaching the event listener to an element higher in the tree allows the shortcut to continue working even after navigation. --- github-apple-option-p-to-preview.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'github-apple-option-p-to-preview.user.js') diff --git a/github-apple-option-p-to-preview.user.js b/github-apple-option-p-to-preview.user.js index 6442a46..7c9dafb 100644 --- a/github-apple-option-p-to-preview.user.js +++ b/github-apple-option-p-to-preview.user.js @@ -23,7 +23,7 @@ var KEY_CODE_P = 80; -document.body.addEventListener( +document.documentElement.addEventListener( 'keydown', function(e) { var node = e.target; -- cgit v1.2.3