aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-09-06 04:28:14 +0200
committerTeddy Wing2020-09-06 04:35:34 +0200
commit3ea5d45e078196d4588332bd67a009ea152a107b (patch)
tree4430bca141d201e7557e80a1bbb5d8cb48aafe5c
parent8796c1f7b3c115bb9e36da5d5500b98e4185f122 (diff)
downloadnetflix-esc-3ea5d45e078196d4588332bd67a009ea152a107b.tar.bz2
Extract key handlers to functions
Reorganise the code a bit to add more separation to the two key handlers.
-rw-r--r--netflix-esc.user.js45
1 files changed, 29 insertions, 16 deletions
diff --git a/netflix-esc.user.js b/netflix-esc.user.js
index 59ca621..4bcf649 100644
--- a/netflix-esc.user.js
+++ b/netflix-esc.user.js
@@ -24,32 +24,45 @@
document.addEventListener(
'keyup',
function(e) {
+ // Close info modal with Escape.
if (
e.key === 'Escape'
|| (e.ctrlKey && e.key === '[')
) {
- var close_button = document.querySelector(
- '[data-uia="previewModal-closebtn"] > [role="button"]'
- );
-
- var click = new MouseEvent(
- 'click',
- { buttons: 1, bubbles: true }
- );
-
- close_button.dispatchEvent(click);
+ info_modal_close();
return;
}
// Show info modal with 'i'.
if (e.key === 'i') {
- var more_info_button = document.querySelector(
- '.mini-modal-container button[data-uia="expand-to-detail-button"]'
- );
-
- var pointer_event = new PointerEvent('pointerdown', { bubbles: true });
- more_info_button.dispatchEvent(pointer_event);
+ info_modal_open();
}
}
);
+
+
+// Click the close button in the info modal.
+function info_modal_close () {
+ var close_button = document.querySelector(
+ '[data-uia="previewModal-closebtn"] > [role="button"]'
+ );
+
+ var click = new MouseEvent(
+ 'click',
+ { buttons: 1, bubbles: true }
+ );
+
+ close_button.dispatchEvent(click);
+}
+
+// Click the "More info" button that appears when a tile is hovered and
+// expanded.
+function info_modal_open () {
+ var more_info_button = document.querySelector(
+ '.mini-modal-container button[data-uia="expand-to-detail-button"]'
+ );
+
+ var pointer_event = new PointerEvent('pointerdown', { bubbles: true });
+ more_info_button.dispatchEvent(pointer_event);
+}