// ==UserScript== // @name 视频拖拽快进后退(终极防干扰版) // @namespace http://tampermonkey.net/ // @version 3.0 // @description 鼠标左右拖拽视频快进后退,拖拽后绝不改变播放状态,保留单击/双击 // @author 豆包 // @match *://*/* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/571779/%E8%A7%86%E9%A2%91%E6%8B%96%E6%8B%BD%E5%BF%AB%E8%BF%9B%E5%90%8E%E9%80%80%EF%BC%88%E7%BB%88%E6%9E%81%E9%98%B2%E5%B9%B2%E6%89%B0%E7%89%88%EF%BC%89.user.js // @updateURL https://update.greasyfork.icu/scripts/571779/%E8%A7%86%E9%A2%91%E6%8B%96%E6%8B%BD%E5%BF%AB%E8%BF%9B%E5%90%8E%E9%80%80%EF%BC%88%E7%BB%88%E6%9E%81%E9%98%B2%E5%B9%B2%E6%89%B0%E7%89%88%EF%BC%89.meta.js // ==/UserScript== (function() { 'use strict'; const DRAG_SPEED = 0.1; const MIN_DRAG = 6; let isDrag = false; let startX = 0; let origTime = 0; let wasPlaying = false; let curVideo = null; let justDragged = false; // 标记刚拖拽过,屏蔽本次点击 // 拖拽结束后屏蔽一次点击,防止网站触发暂停 function blockClickOnce() { justDragged = true; setTimeout(() => { justDragged = false; }, 100); } function init(video) { if (video.dataset.dragInited) return; video.dataset.dragInited = '1'; // 拦截点击:如果刚拖拽过,阻止本次点击(核心修复) video.addEventListener('click', e => { if (justDragged) { e.preventDefault(); e.stopPropagation(); return; } }, true); // 捕获模式优先执行 // 鼠标按下 video.addEventListener('mousedown', e => { if (e.button !== 0) return; isDrag = false; startX = e.clientX; curVideo = video; origTime = video.currentTime; wasPlaying = !video.paused; }); // 拖拽移动 video.addEventListener('mousemove', e => { if (!curVideo || e.button !== 0) return; const dx = e.clientX - startX; if (Math.abs(dx) < MIN_DRAG) return; isDrag = true; e.preventDefault(); e.stopPropagation(); const t = origTime + dx * DRAG_SPEED; curVideo.currentTime = Math.max(0, Math.min(t, curVideo.duration || 0)); }); // 结束拖拽 function end() { if (!curVideo) return; if (isDrag) { blockClickOnce(); // 屏蔽本次点击 // 强制恢复状态,延迟执行确保覆盖网站逻辑 setTimeout(() => { wasPlaying ? curVideo.play().catch(()=>{}) : curVideo.pause(); }, 0); } isDrag = false; curVideo = null; } video.addEventListener('mouseup', end); video.addEventListener('mouseleave', end); } // 初始化所有视频 document.querySelectorAll('video').forEach(init); // 监听动态视频 new MutationObserver(muts => { muts.forEach(m => { m.addedNodes.forEach(n => { if (n.tagName === 'VIDEO') init(n); n.querySelectorAll?.('video').forEach(init); }); }); }).observe(document.body, { childList: true, subtree: true }); })();