Created
July 15, 2024 19:50
-
-
Save prednaz/28b90e269c3870f041020e9e01df78ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name video_speed_controls | |
// @match *://www.youtube.com/* | |
// @match *://pr0gramm.com/* | |
// @match *://www.amazon.de/* | |
// @match file:///* | |
// @grant none | |
// ==/UserScript== | |
const traverse_videos = (f) => {Array.from(document.getElementsByTagName("video")).forEach(f)}; | |
document.addEventListener( | |
"keydown", | |
(event) => | |
{ | |
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {return;} | |
switch (event.key) { | |
case "p": | |
case "e": { | |
traverse_videos(v => {v.playbackRate += .25}); | |
break; | |
} | |
case "[": | |
case "w": { | |
traverse_videos(v => {v.playbackRate -= .25}); | |
break; | |
} | |
case "-": | |
case "2": { | |
traverse_videos(v => {v.playbackRate = 2}); | |
break; | |
} | |
case "0": | |
case "3": { | |
traverse_videos(v => {v.playbackRate = 3}); | |
break; | |
} | |
case "4": { | |
traverse_videos(v => {v.playbackRate = 4}); | |
break; | |
} | |
case "=": | |
case "1": { | |
traverse_videos(v => {v.playbackRate = 1}); | |
break; | |
} | |
case "x": { | |
traverse_videos(v => {v.fastSeek(v.duration)}); | |
break; | |
} | |
case "a": { | |
traverse_videos(v => {v.fastSeek(v.currentTime - 12)}); | |
break; | |
} | |
case "s": { | |
traverse_videos(v => {v.fastSeek(v.currentTime + 12)}); | |
break; | |
} | |
default: { | |
return; | |
} | |
} | |
event.preventDefault(); | |
event.stopPropagation(); | |
}, | |
true | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment