Fullscreen Video Speed Controller

Control playback speed, fix A/V sync issues, and seek for fullscreen videos

当前为 2025-05-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fullscreen Video Speed Controller
  3. // @version 2.0.0
  4. // @description Control playback speed, fix A/V sync issues, 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) {
  38. video.playbackRate = speed;
  39. }
  40. }
  41.  
  42. // Function to seek the video forward or backward
  43. function seekVideo(offset) {
  44. const video = getFullscreenVideo();
  45. if (video) {
  46. video.currentTime += offset;
  47. }
  48. }
  49.  
  50. // Event listeners for key presses
  51. document.addEventListener('keydown', function(event) {
  52. switch(event.key) {
  53. case 'j':
  54. setVideoSpeed(1.00);
  55. break;
  56. case 'k':
  57. setVideoSpeed(2);
  58. break;
  59. case 'l':
  60. setVideoSpeed(3.00);
  61. break;
  62. case 'i': // Fix audio/video synchronization issues
  63. seekVideo(0.00001);
  64. break;
  65. case 'h':
  66. seekVideo(-5); // Rewind 5 seconds
  67. break;
  68. case ';':
  69. seekVideo(5); // Fast-forward 5 seconds
  70. break;
  71. }
  72. });
  73. })();