Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript: (function() {
- var speeds = [1, 1.5, 2];
- var currentSpeedIndex = parseInt(localStorage.getItem('videoSpeedIndex') || '0');
- function showFixedSpeedIndicator(message, duration) {
- var speedIndicator = document.querySelector('.fixed-speed-indicator');
- if (!speedIndicator) {
- speedIndicator = document.createElement('div');
- speedIndicator.className = 'fixed-speed-indicator';
- 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;';
- document.body.appendChild(speedIndicator);
- }
- speedIndicator.textContent = message;
- speedIndicator.style.opacity = '1';
- speedIndicator.style.display = 'block';
- setTimeout(function() {
- speedIndicator.style.opacity = '0';
- setTimeout(() => {
- speedIndicator.style.display = 'none';
- }, 300);
- }, duration);
- }
- function applyToVideo(v, showIndicator = false) {
- if (v.playbackRate !== undefined) {
- v.playbackRate = speeds[currentSpeedIndex];
- if (showIndicator) {
- if (!window.location.href.includes('rutube.ru/shorts/') && !window.location.href.includes('dzen.ru') && !window.location.href.includes('my.mail.ru') && !window.location.href.includes('pikabu.ru') && !window.location.href.includes('store.steampowered.com') && !window.location.href.includes('wink.ru')) {
- var container = v.closest('.jwplayer') || v.closest('.video_box_wrap') || v.closest('.player') || v.closest('.vjs_video') || v.closest('.video-js') || v.parentElement;
- container.style.position = 'relative';
- var speedIndicator = container.querySelector('.speed-indicator');
- if (!speedIndicator) {
- speedIndicator = document.createElement('div');
- speedIndicator.className = 'speed-indicator';
- 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;';
- container.appendChild(speedIndicator);
- }
- speedIndicator.textContent = v.playbackRate.toFixed(1) + 'x';
- speedIndicator.style.opacity = '1';
- speedIndicator.style.display = 'block';
- setTimeout(() => {
- speedIndicator.style.opacity = '0';
- setTimeout(() => {
- speedIndicator.style.display = 'none';
- }, 300);
- }, 1000);
- } else {
- showFixedSpeedIndicator(v.playbackRate.toFixed(1) + 'x', 1000);
- }
- }
- }
- }
- function changeSpeed() {
- var videos = document.querySelectorAll('video');
- if (videos.length > 0) {
- var currentSpeed = videos[0].playbackRate;
- var currentIndex = speeds.indexOf(currentSpeed);
- if (currentIndex === -1) {
- currentIndex = speeds.findIndex(speed => speed > currentSpeed) - 1;
- if (currentIndex === -2) currentIndex = speeds.length - 1;
- }
- currentSpeedIndex = (currentIndex + 1) % speeds.length;
- localStorage.setItem('videoSpeedIndex', currentSpeedIndex);
- videos.forEach(v => applyToVideo(v, true));
- } else {
- showFixedSpeedIndicator('No video found on this page', 2000);
- }
- }
- function handleNewVideos(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes) {
- mutation.addedNodes.forEach(function(node) {
- if (node.nodeName === 'VIDEO') {
- applyToVideo(node, false);
- } else if (node.classList && (node.classList.contains('jwplayer') || node.classList.contains('player') || node.classList.contains('vjs_video') || node.classList.contains('video-js'))) {
- var video = node.querySelector('video');
- if (video) {
- applyToVideo(video, false);
- }
- } else if (node.querySelector) {
- var videos = node.querySelectorAll('video');
- videos.forEach(v => applyToVideo(v, false));
- }
- });
- }
- });
- }
- function checkAndApplySpeed() {
- document.querySelectorAll('video').forEach(v => {
- if (v.playbackRate !== speeds[currentSpeedIndex]) {
- applyToVideo(v, false);
- }
- });
- }
- document.addEventListener('seeked', function(e) {
- if (e.target.tagName === 'VIDEO') {
- setTimeout(() => applyToVideo(e.target, false), 0);
- }
- }, true);
- ['loadedmetadata', 'canplay', 'playing'].forEach(function(event) {
- document.addEventListener(event, function(e) {
- if (e.target.tagName === 'VIDEO') {
- applyToVideo(e.target, false);
- }
- }, true);
- });
- var observer = new MutationObserver(handleNewVideos);
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- var videos = document.querySelectorAll('video');
- if (videos.length > 0) {
- var currentSpeed = videos[0].playbackRate;
- var currentIndex = speeds.indexOf(currentSpeed);
- if (currentIndex === -1) {
- currentIndex = speeds.findIndex(speed => speed > currentSpeed) - 1;
- if (currentIndex === -2) currentIndex = speeds.length - 1;
- }
- currentSpeedIndex = currentIndex;
- localStorage.setItem('videoSpeedIndex', currentSpeedIndex);
- }
- videos.forEach(v => applyToVideo(v, false));
- document.addEventListener('play', function(e) {
- if (e.target.tagName === 'VIDEO') {
- applyToVideo(e.target, false);
- }
- }, true);
- window.addEventListener('popstate', checkAndApplySpeed);
- changeSpeed();
- })();
Advertisement
Add Comment
Please, Sign In to add comment