aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzrose584 <57181548+zrose584@users.noreply.github.com>2020-09-09 21:01:16 +0200
committerzrose584 <57181548+zrose584@users.noreply.github.com>2020-09-09 21:01:16 +0200
commit12e56c7e71599d0e5bd31454bd92d2e5155786e6 (patch)
tree7ec573f7f6473912d2c8ba9371ec252e2655f64a
parent3a8f18a1fd8d50cce2a798d44699e9c7da48f331 (diff)
downloadyt-local-12e56c7e71599d0e5bd31454bd92d2e5155786e6.tar.lz
yt-local-12e56c7e71599d0e5bd31454bd92d2e5155786e6.tar.xz
yt-local-12e56c7e71599d0e5bd31454bd92d2e5155786e6.zip
add hotkeys.js
-rw-r--r--youtube/static/js/hotkeys.js32
-rw-r--r--youtube/templates/watch.html4
2 files changed, 35 insertions, 1 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
diff --git a/youtube/templates/watch.html b/youtube/templates/watch.html
index 01ae8cb..f0dcb8d 100644
--- a/youtube/templates/watch.html
+++ b/youtube/templates/watch.html
@@ -553,7 +553,7 @@ Reload without invidious (for usage of new identity button).</a>
// where in relation to the edge of the viewport, we are observing
rootMargin: "100px",
- // how much of the element needs to have intersected
+ // how much of the element needs to have intersected
// in order to fire our loading function
threshold: 1.0
@@ -608,4 +608,6 @@ Reload without invidious (for usage of new identity button).</a>
</details>
{% endif %}
{% endif %}
+
+ <script src="/youtube.com/static/js/hotkeys.js"></script>
{% endblock main %}