From 12e56c7e71599d0e5bd31454bd92d2e5155786e6 Mon Sep 17 00:00:00 2001 From: zrose584 <57181548+zrose584@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:01:16 +0200 Subject: add hotkeys.js --- youtube/static/js/hotkeys.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 youtube/static/js/hotkeys.js (limited to 'youtube/static/js') diff --git a/youtube/static/js/hotkeys.js b/youtube/static/js/hotkeys.js new file mode 100644 index 0000000..45e4333 --- /dev/null +++ b/youtube/static/js/hotkeys.js @@ -0,0 +1,32 @@ +Q = document.querySelector.bind(document); + +function onKeyDown(e) { + if (['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return false; + + console.log(e); + let v = Q("video"); + let c = e.key.toLowerCase(); + if (c == "k") { + v.paused ? v.play() : v.pause(); + } + else if (c == "arrowleft") { + e.preventDefault(); + v.currentTime = v.currentTime - 5; + } + else if (c == "arrowright") { + e.preventDefault(); + v.currentTime = v.currentTime + 5; + } + else if (c == "j") { + e.preventDefault(); + v.currentTime = v.currentTime - 10; + } + else if (c == "l") { + e.preventDefault(); + v.currentTime = v.currentTime + 10; + } +} + +window.addEventListener('load', function() { + document.addEventListener('keydown', onKeyDown); +}); \ No newline at end of file -- cgit v1.2.3