Fullscreen Video Speed Controller

Control playback speed, and seek for fullscreen videos

  1. // ==UserScript==
  2. // @name Fullscreen Video Speed Controller
  3. // @version 2.1.1
  4. // @description Control playback speed, and seek for fullscreen videos
  5. // @author Wanten
  6. // @copyright 2025 Wanten
  7. // @license MIT
  8. // @supportURL https://gist.github.com/WantenMN/c0afabc32a911d4dd10e06cff6bcb211
  9. // @homepageURL https://gist.github.com/WantenMN/c0afabc32a911d4dd10e06cff6bcb211
  10. // @namespace https://greasyfork.org/en/scripts/536243
  11. // @run-at document-end
  12. // @match https://*/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // Helper function to get the fullscreen video element
  20. function getFullscreenVideo() {
  21. if (document.fullscreenElement && document.fullscreenElement.tagName === 'VIDEO') {
  22. return document.fullscreenElement;
  23. }
  24.  
  25. const videos = document.getElementsByTagName('video');
  26. for (const video of videos) {
  27. if (video.offsetWidth === window.innerWidth && video.offsetHeight === window.innerHeight) {
  28. return video;
  29. }
  30. }
  31. return null;
  32. }
  33.  
  34. // Function to set the video speed
  35. function setVideoSpeed(speed) {
  36. const video = getFullscreenVideo();
  37. if (video && video.playbackRate != speed) {
  38. video.playbackRate = speed;
  39.  
  40. if (video.playbackRate === 1){
  41. // Fix audio/video synchronization issues
  42. video.currentTime = video.currentTime;
  43. }
  44. }
  45. }
  46.  
  47. // Function to seek the video forward or backward
  48. function seekVideo(offset) {
  49. const video = getFullscreenVideo();
  50. if (video) {
  51. video.currentTime += offset;
  52. }
  53. }
  54.  
  55. // Event listeners for key presses
  56. document.addEventListener('keydown', function(event) {
  57. switch(event.key) {
  58. case 'j':
  59. setVideoSpeed(1);
  60. break;
  61. case 'k':
  62. setVideoSpeed(2);
  63. break;
  64. case 'l':
  65. setVideoSpeed(3);
  66. break;
  67. case 'h':
  68. seekVideo(-5); // Rewind 5 seconds
  69. break;
  70. case ';':
  71. seekVideo(5); // Fast-forward 5 seconds
  72. break;
  73. }
  74. });
  75. })();
  76.