// ==UserScript== // @name 优课联盟禁用移出暂停,静音二倍速 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 禁用鼠标移出视频区域暂停功能 // @author YourName // @match *://*.uooc.net.cn/* // @grant none // @run-at document-end // ==/UserScript== (function() { 'use strict'; const INTERVAL_DELAY = 500; const OBSERVER_CONFIG = { childList: true, subtree: true }; // 处理目标节点 function handleTarget(node) { // 阻止mouseout事件传播 node.addEventListener('mouseout', e => { e.stopImmediatePropagation(); e.preventDefault(); }, true); // 额外防御:尝试移除可能存在的暂停逻辑 const cloneListener = node.onmouseout; if (cloneListener) { node.onmouseout = null; setTimeout(() => node.onmouseout = cloneListener, 100); } } // 初始化监视 let observer = new MutationObserver(mutations => { // 通过不同选择器尝试定位视频容器 const selectors = [ '.video-wrapper', '.video-container', 'div[class*="video"]', 'div[id*="player"]' ]; selectors.forEach(selector => { document.querySelectorAll(selector).forEach(handleTarget); }); }); // 启动监视 observer.observe(document.body, OBSERVER_CONFIG); // 定期检查防漏 setInterval(() => { document.querySelectorAll('video, .video-player').forEach(video => { if (video.__protected) return; video.__protected = true; video.addEventListener('pause', e => { if (e.type === 'pause' && !video.paused) { video.play().catch(() => {}); } }); }); }, INTERVAL_DELAY); })(); //自动下一节 (function() { 'use strict'; // 检测并点击下一节按钮 function clickNext() { // 通过按钮文字查找下一节按钮(根据实际页面调整选择器) const nextButtons = Array.from(document.querySelectorAll('a, button')); const nextBtn = nextButtons.find(el => el.innerText.includes('下一节') || el.innerText.includes('下一章') || el.innerText.includes('Next') ); if (nextBtn) { console.log('找到下一节按钮,自动跳转...'); nextBtn.click(); } else { console.log('未找到下一节按钮,请手动操作'); } } // 检测视频播放状态 function checkVideo() { const video = document.querySelector('video'); if (video) { // 监听视频结束事件 video.addEventListener('ended', () => { console.log('当前视频播放完毕'); setTimeout(clickNext, 3000); // 3秒后跳转 }); } else { // 如果没找到视频元素,5秒后重试 setTimeout(checkVideo, 5000); } } // 页面加载完成后开始检测 window.addEventListener('load', checkVideo); // 监听SPA页面变化(针对单页应用) new MutationObserver(checkVideo).observe(document.body, { childList: true, subtree: true }); })(); (function() { 'use strict'; // 覆盖页面可见性属性 Object.defineProperty(document, 'visibilityState', { get: () => 'visible' }); Object.defineProperty(document, 'hidden', { get: () => false }); // 拦截visibilitychange事件 const originalAddEventListener = EventTarget.prototype.addEventListener; EventTarget.prototype.addEventListener = function(type, listener, options) { if (type === 'visibilitychange') return; originalAddEventListener.call(this, type, listener, options); }; // 增强的视频控制函数 function enhanceVideoControl(video) { if (video.dataset.enhanced) return; // 劫持暂停方法 video._originalPause = video.pause; video.pause = () => console.log('[防暂停] 已拦截暂停操作'); // 劫持播放方法 video._originalPlay = video.play; video.play = function() { this.muted = true; // 强制静音 this.playbackRate = 2; // 强制2倍速 return this._originalPlay(); }; // 立即应用设置 video.muted = true; video.playbackRate = 2; video.dataset.enhanced = 'true'; // 自动恢复播放 if (video.paused) video.play().catch(e => {}); } // DOM观察器 new MutationObserver(mutations => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { if (node.nodeType === 1) { node.querySelectorAll('video').forEach(enhanceVideoControl); } }); }); }).observe(document.documentElement, { childList: true, subtree: true }); // 初始化处理现有视频 document.querySelectorAll('video').forEach(enhanceVideoControl); // 定时巡检(每秒执行) setInterval(() => { document.querySelectorAll('video').forEach(video => { // 强制保持2倍速 if (video.playbackRate !== 2) video.playbackRate = 2; // 强制静音 if (!video.muted) video.muted = true; // 自动恢复播放 if (video.paused && !video.ended) video.play().catch(e => {}); }); }, 1000); })();