Last active
October 9, 2020 18:57
-
-
Save SoyOscarRH/b3d5d4864b2fb1db2f3652f532f51b0a to your computer and use it in GitHub Desktop.
JavaScript code to change the speed videos on the internet using "[" and "]".
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
const getAllVideos = () => Array.from(document.getElementsByTagName("video")); | |
const changeSpeedAllVideos = ({ to }) => { | |
to = Math.min(Math.max(to, 0.5), 6); | |
getAllVideos().forEach((video) => (video.playbackRate = to)); | |
console.log("new playback speed is " + to.toFixed(2)); | |
}; | |
const changeSpeedSlightly = ({ key }) => { | |
const videos = getAllVideos(); | |
const currentSpeed = videos[0].playbackRate; | |
if (key === "[") changeSpeedAllVideos({ to: currentSpeed - 0.15 }); | |
if (key === "]") changeSpeedAllVideos({ to: currentSpeed + 0.15 }); | |
}; | |
getAllVideos().forEach((video) => (video.playbackRate = 1)); | |
document.body.addEventListener("keypress", changeSpeedSlightly); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment