ozhegovvv

video speed control 1-99x

Sep 2nd, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:(function() {
  2. var speed = 1.5;
  3. var userSpeed = parseFloat(prompt("Enter playback speed (e.g., 1.5):", speed));
  4. if (!isNaN(userSpeed) && userSpeed > 0) {
  5.     speed = userSpeed;
  6. }
  7.  
  8. function showFixedSpeedIndicator(message, duration) {
  9.     if (window.location.href.includes('rutube.ru/shorts/') || window.location.href.includes('dzen.ru') || window.location.href.includes('my.mail.ru')) {
  10.         var speedIndicator = document.querySelector('.fixed-speed-indicator');
  11.         if (!speedIndicator) {
  12.             speedIndicator = document.createElement('div');
  13.             speedIndicator.className = 'fixed-speed-indicator';
  14.             speedIndicator.style.cssText = 'position:fixed;top:0px;left:50%;transform:translateX(-50%);background-color:rgba(0,0,0,0.7);color:white;padding:0 1px;border-radius:0 0 3px 3px;font-size:14px;font-family:Arial,sans-serif;z-index:999999;transition:opacity 0.3s;opacity:0;display:none;';
  15.             document.body.appendChild(speedIndicator);
  16.         }
  17.  
  18.         speedIndicator.textContent = message;
  19.         speedIndicator.style.opacity = '1';
  20.         speedIndicator.style.display = 'block';
  21.        
  22.         setTimeout(function() {
  23.             speedIndicator.style.opacity = '0';
  24.             setTimeout(() => {
  25.                 speedIndicator.style.display = 'none';
  26.             }, 300);
  27.         }, duration);
  28.     }
  29. }
  30.  
  31. function applyToVideo(v, showIndicator = false) {
  32.     if (v.playbackRate !== undefined) {
  33.         v.playbackRate = speed;
  34.  
  35.         if (showIndicator) {
  36.             if (!window.location.href.includes('rutube.ru/shorts/') && !window.location.href.includes('dzen.ru') && !window.location.href.includes('my.mail.ru')) {
  37.                 var container = v.closest('.jwplayer') || v.closest('.video_box_wrap') || v.closest('.player') || v.parentElement;
  38.                 container.style.position = 'relative';
  39.  
  40.                 var speedIndicator = container.querySelector('.speed-indicator');
  41.                 if (!speedIndicator) {
  42.                     speedIndicator = document.createElement('div');
  43.                     speedIndicator.className = 'speed-indicator';
  44.                     speedIndicator.style.cssText = 'position:absolute;top:0px;left:50%;transform:translateX(-50%);background-color:rgba(0,0,0,0.7);color:white;padding:0 1px;border-radius:0 0 3px 3px;font-size:14px;font-family:Arial,sans-serif;z-index:999999;transition:opacity 0.3s;opacity:0;display:none;';
  45.                     container.appendChild(speedIndicator);
  46.                 }
  47.  
  48.                 speedIndicator.textContent = v.playbackRate.toFixed(1) + 'x';
  49.                 speedIndicator.style.opacity = '1';
  50.                 speedIndicator.style.display = 'block';
  51.                 setTimeout(() => {
  52.                     speedIndicator.style.opacity = '0';
  53.                     setTimeout(() => {
  54.                         speedIndicator.style.display = 'none';
  55.                     }, 300);
  56.                 }, 1000);
  57.             } else {
  58.                 showFixedSpeedIndicator(v.playbackRate.toFixed(1) + 'x', 1000);
  59.             }
  60.         }
  61.     }
  62. }
  63.  
  64. function handleNewVideos(mutations) {
  65.     mutations.forEach(function(mutation) {
  66.         if (mutation.addedNodes) {
  67.             mutation.addedNodes.forEach(function(node) {
  68.                 if (node.nodeName === 'VIDEO') {
  69.                     applyToVideo(node, false);
  70.                 } else if (node.classList && (node.classList.contains('jwplayer') || node.classList.contains('player'))) {
  71.                     var video = node.querySelector('video');
  72.                     if (video) {
  73.                         applyToVideo(video, false);
  74.                     }
  75.                 } else if (node.querySelector) {
  76.                     var videos = node.querySelectorAll('video');
  77.                     videos.forEach(v => applyToVideo(v, false));
  78.                 }
  79.             });
  80.         }
  81.     });
  82. }
  83.  
  84. function checkAndApplySpeed() {
  85.     document.querySelectorAll('video').forEach(v => {
  86.         if (v.playbackRate !== speed) {
  87.             applyToVideo(v, false);
  88.         }
  89.     });
  90. }
  91.  
  92. document.addEventListener('seeked', function(e) {
  93.     if (e.target.tagName === 'VIDEO') {
  94.         setTimeout(() => applyToVideo(e.target, false), 0);
  95.     }
  96. }, true);
  97.  
  98. ['loadedmetadata', 'canplay', 'playing'].forEach(function(event) {
  99.     document.addEventListener(event, function(e) {
  100.         if (e.target.tagName === 'VIDEO') {
  101.             applyToVideo(e.target, false);
  102.         }
  103.     }, true);
  104. });
  105.  
  106. var observer = new MutationObserver(handleNewVideos);
  107.  
  108. observer.observe(document.body, {
  109.     childList: true,
  110.     subtree: true
  111. });
  112.  
  113. document.querySelectorAll('video').forEach(v => applyToVideo(v, true));
  114.  
  115. document.addEventListener('play', function(e) {
  116.     if (e.target.tagName === 'VIDEO') {
  117.         applyToVideo(e.target, false);
  118.     }
  119. }, true);
  120.  
  121. window.addEventListener('popstate', checkAndApplySpeed);
  122. })();
Tags: bookmark
Advertisement
Add Comment
Please, Sign In to add comment