aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/static/js/hotkeys.js
diff options
context:
space:
mode:
authorJames Taylor <28744867+user234683@users.noreply.github.com>2020-09-09 18:37:29 -0700
committerGitHub <noreply@github.com>2020-09-09 18:37:29 -0700
commit75171b7bd5e8a482702c2eb7b132af75b690b2cc (patch)
tree7ec573f7f6473912d2c8ba9371ec252e2655f64a /youtube/static/js/hotkeys.js
parent3a8f18a1fd8d50cce2a798d44699e9c7da48f331 (diff)
parent12e56c7e71599d0e5bd31454bd92d2e5155786e6 (diff)
downloadyt-local-75171b7bd5e8a482702c2eb7b132af75b690b2cc.tar.lz
yt-local-75171b7bd5e8a482702c2eb7b132af75b690b2cc.tar.xz
yt-local-75171b7bd5e8a482702c2eb7b132af75b690b2cc.zip
Merge pull request #13 from zrose584/master
add hotkeys.js
Diffstat (limited to 'youtube/static/js/hotkeys.js')
-rw-r--r--youtube/static/js/hotkeys.js32
1 files changed, 32 insertions, 0 deletions
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