Created
June 2, 2023 11:07
-
-
Save MicahZoltu/3a69b6bfd44893b886cf36ee57284cb4 to your computer and use it in GitHub Desktop.
Faster Video Playback Bookmarklet
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
javascript:(() => { let speed = 2; let indicator; let indicatorTimeout; function createIndicator() { indicator = document.createElement("div"); indicator.setAttribute(`style`, ` position: fixed; left: 15px; top: 15px; background-color: black; color: white; font-size: 20px; padding: 10px; display: none; z-index: 99999999999999; `); document.body.appendChild(indicator); }; function show(text) { if (!indicator) createIndicator(); indicator.innerText = text; indicator.style.display = "block"; indicatorTimeout && clearTimeout(indicatorTimeout); indicatorTimeout = setTimeout(() => { indicator.style.display = "none"; }, 5000); } function round(value, precision) { const scalar = 10 ** precision; return Math.round(value * scalar) / scalar; }; function conformSpeed(value) { return Math.min(Math.max(value, 1 / 16), 16); }; function syncSpeed() { document.querySelectorAll("video").forEach(video => { video.playbackRate = speed; }); }; function changeSpeed(value) { speed = conformSpeed(value); show(round(speed, 2).toString()); syncSpeed(); }; setInterval(syncSpeed, 3000); window.addEventListener("keydown", e => { if (e.code === "KeyA") { changeSpeed(5); e.stopImmediatePropagation(); } else if (e.code === "KeyS") { changeSpeed(speed - 0.1); e.stopImmediatePropagation(); } else if (e.code === "KeyD") { changeSpeed(2); e.stopImmediatePropagation(); } else if (e.code === "KeyF") { changeSpeed(speed + 0.1); e.stopImmediatePropagation(); } }, {capture: true}); })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment