diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-09-19 15:33:11 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2024-09-19 15:33:11 +0530 |
commit | a4e01da27c08e43a67b2618ad1e71c1f8f86d5cd (patch) | |
tree | 5b8f407dbb7e9d1ab2106ac0cc8564897e7a2098 /youtube/static/js/hotkeys.js | |
download | yt-local-master.tar.gz yt-local-master.tar.bz2 yt-local-master.zip |
Diffstat (limited to 'youtube/static/js/hotkeys.js')
-rw-r--r-- | youtube/static/js/hotkeys.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/youtube/static/js/hotkeys.js b/youtube/static/js/hotkeys.js new file mode 100644 index 0000000..b71972e --- /dev/null +++ b/youtube/static/js/hotkeys.js @@ -0,0 +1,61 @@ +function onKeyDown(e) { + if (['INPUT', 'TEXTAREA'].includes(document.activeElement.tagName)) return false; + + // console.log(e); + let v = QId("js-video-player"); + if (!e.isTrusted) return; // plyr CustomEvent + let c = e.key.toLowerCase(); + if (e.ctrlKey) return; + else 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; + } + else if (c == "f") { + e.preventDefault(); + if (data.settings.use_video_player == 2) { + player.fullscreen.toggle() + } + else { + if (document.fullscreen) { + document.exitFullscreen() + } + else { + v.requestFullscreen() + } + } + } + else if (c == "m") { + if (v.muted == false) {v.muted = true;} + else {v.muted = false;} + } + else if (c == "c") { + e.preventDefault(); + let tt = getActiveTranscriptTrack(); + if (tt == null) return; + if (tt.mode == "showing") tt.mode = "disabled"; + else tt.mode = "showing"; + } + else if (c == "t") { + let ts = Math.floor(QId("js-video-player").currentTime); + copyTextToClipboard(`https://youtu.be/${data.video_id}?t=${ts}`); + } +} + +window.addEventListener('DOMContentLoaded', function() { + document.addEventListener('keydown', onKeyDown); +}); |