// ==UserScript== // @name 115网盘视频自动接管 - 移动端版 // @namespace https://github.com/mason173/aira-browser // @version 1.2.1 // @description 115网盘播放视频时,自动进入「网页视频接管 - 移动端版」脚本的全屏接管模式。需要先安装主脚本。 // @author Video Takeover // @icon https://115.com/favicon.ico // @match https://115.com/players/video/* // @match https://115.com/players/magnet/* // @match https://115.com/web/lixian/master/video/* // @match https://115.com/web/lixian/master/magnet/* // @match https://115.com/?ct=* // @match https://115.com/?aid=* // @match https://115.com/?pick_code=* // @match https://115vod.com/* // @grant none // @run-at document-idle // @license GPL-3.0 // ==/UserScript== (function () { 'use strict'; const CONFIG = { // 等待主脚本悬浮按钮出现的超时时间(毫秒) waitTimeout: 15000, // 轮询间隔(毫秒) pollInterval: 300, // 接管成功后是否自动播放 autoPlay: true, }; let triggered = false; // 全局监听:接管容器一出现(不管自动还是手动触发),就移到 html 根节点下 // 绕开网站祖先元素的 transform/filter,避免 position:fixed 失效 const fixObserver = new MutationObserver(() => { const container = document.querySelector('.vt-takeover-container'); if (container && container.parentNode === document.body) { document.documentElement.appendChild(container); console.log('[115自动接管] 接管容器已移至 html 根节点,CSS 模式全屏修复生效。'); } }); fixObserver.observe(document.documentElement, { childList: true, subtree: true }); function triggerTakeover() { if (triggered) return; // 优先通过主脚本暴露的悬浮按钮触发(与手动点击行为一致,最稳定) const fullscreenBtn = document.querySelector('.vt-float-btn.vt-btn-fullscreen'); if (fullscreenBtn) { triggered = true; fullscreenBtn.click(); // 接管后自动播放 if (CONFIG.autoPlay) { setTimeout(() => { const video = document.querySelector('video'); if (video && video.paused) { video.play().catch(() => {}); } }, 500); } return true; } return false; } function waitAndTrigger() { const startTime = Date.now(); const tryTrigger = () => { if (triggered) return; // 先确保有 video 元素,再尝试触发 const video = document.querySelector('video'); if (!video) { if (Date.now() - startTime < CONFIG.waitTimeout) { setTimeout(tryTrigger, CONFIG.pollInterval); } return; } if (triggerTakeover()) return; // 悬浮按钮还没出现,继续等 if (Date.now() - startTime < CONFIG.waitTimeout) { setTimeout(tryTrigger, CONFIG.pollInterval); } else { console.warn('[115自动接管] 超时:未找到网页视频接管的悬浮按钮,请确认主脚本已安装并启用。'); } }; tryTrigger(); } // 启动 if (document.readyState === 'complete' || document.readyState === 'interactive') { setTimeout(waitAndTrigger, 500); } else { document.addEventListener('DOMContentLoaded', () => { setTimeout(waitAndTrigger, 500); }); } // 有些 115 页面是 SPA,视频可能后加载,额外监听 URL 变化 let lastUrl = location.href; const observer = new MutationObserver(() => { if (location.href !== lastUrl) { lastUrl = location.href; triggered = false; setTimeout(waitAndTrigger, 800); } }); observer.observe(document.body, { childList: true, subtree: true }); console.log('[115自动接管] 脚本已加载,等待视频出现后自动进入全屏接管模式。'); })();