// ==UserScript== // @name 同创全自动学习助手(后台计时修复版) // @namespace http://tampermonkey.net/ // @version 5.0 // @description 强制后台播放 + 后台时长欺骗 + 自动下一节(修复计时不增长) // @match *://*.strong365.com/* // @match *://yun.strong365.com/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; const CHECK_INTERVAL = 2000; // 检测弹窗间隔(ms) const NEXT_KEYWORDS = ['学习下一节', '下一节', '继续学习', 'Next', '继续']; let video = null; let retryCount = 0; const MAX_RETRY = 30; // ---------- 核心伪装:让页面以为自己永远在前台 ---------- function fakeVisibility() { // 覆盖 document.hidden const hiddenDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'hidden'); if (hiddenDescriptor) { Object.defineProperty(document, 'hidden', { get: () => false, configurable: true }); } else { // 直接覆盖 Object.defineProperty(document, 'hidden', { value: false, writable: false }); } // 覆盖 document.visibilityState const visDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState'); if (visDescriptor) { Object.defineProperty(document, 'visibilityState', { get: () => 'visible', configurable: true }); } else { Object.defineProperty(document, 'visibilityState', { value: 'visible', writable: false }); } // 重写 hasFocus() document.hasFocus = () => true; // 拦截 visibilitychange 事件,让它根本不触发回调 document.addEventListener('visibilitychange', function(e) { e.stopImmediatePropagation(); }, true); // 补充:某些页面可能通过 onfocus/onblur 检测,也阻止冒泡 window.addEventListener('blur', e => e.stopImmediatePropagation(), true); window.addEventListener('focus', e => e.stopImmediatePropagation(), true); } // 定期重新伪装,防止页面动态复原 function keepFaking() { fakeVisibility(); } // ---------- 安全查找视频 ---------- function findVideo() { try { const iframe = document.querySelector('.iframe-box iframe'); if (iframe) { try { const v = iframe.contentDocument.querySelector('video'); if (v) return v; } catch(e) {} } return document.querySelector('video'); } catch(e) { return null; } } function ensureVideo() { if (!video || !document.contains(video)) { video = findVideo(); if (video) console.log('🔄 视频重新捕获'); } return video; } // ---------- 强制播放 ---------- function forcePlay() { try { const v = ensureVideo(); if (v && typeof v.play === 'function' && v.paused) { v.play().catch(err => console.warn('播放恢复失败:', err)); } } catch(e) {} } // ---------- 自动点击“学习下一节” ---------- function clickNextButton() { try { let doc = document; const iframe = document.querySelector('.iframe-box iframe'); if (iframe) { try { doc = iframe.contentDocument || iframe.contentWindow.document; } catch(e) {} } const allElements = doc.querySelectorAll( 'button, a, input[type="button"], input[type="submit"], ' + '[role="button"], .btn, .button, .el-button, .el-btn, ' + 'div[class*="btn"], span[class*="btn"], ' + '.next, .next-btn, .continue-btn, .submit-btn, .confirm-btn, ' + '.dialog-footer button, .modal-footer button, .el-dialog__footer button, ' + '.layui-layer-btn button, .layui-layer-btn a' ); for (let el of allElements) { const text = (el.textContent || el.innerText || '').trim(); if (!text) continue; const matched = NEXT_KEYWORDS.some(kw => text.toLowerCase().includes(kw.toLowerCase())); if (!matched) continue; // 由于我们伪装了可见性,按钮不应因 tab 隐藏而不可见,但仍检查尺寸 const rect = el.getBoundingClientRect(); if (rect.width === 0 && rect.height === 0) continue; // 真正不可见 el.click(); console.log('🎯 已自动点击“' + text + '”'); setTimeout(() => { video = findVideo(); }, 500); return true; } return false; } catch(e) { return false; } } // ---------- 初始化 ---------- function init() { // 立即执行一次伪装 fakeVisibility(); // 定期更新伪装,防止页面重置 setInterval(keepFaking, 1000); const v = findVideo(); if (!v) { if (retryCount++ < MAX_RETRY) { setTimeout(init, 1000); } else { console.warn('⚠️ 未找到视频元素,可能页面未完全加载'); } return; } video = v; console.log('✅ 已捕获视频元素'); // ---- 后台播放 ---- setInterval(forcePlay, 500); window.addEventListener('blur', () => setTimeout(forcePlay, 100)); // 拦截播放器 pause const playerNames = ['player', 'aliplayer', 'Aliplayer', 'videoPlayer']; playerNames.forEach(name => { if (window[name] && typeof window[name].play === 'function') { const origPause = window[name].pause; if (origPause) { window[name].pause = function() { if (document.hidden) { // 已被伪装,其实不会 true console.log('🛡️ 拦截了播放器暂停请求'); return; } return origPause.apply(this, arguments); }; console.log(`✅ 拦截了播放器对象 ${name}.pause`); } } }); // 视频自身的 pause video.addEventListener('pause', function() { this.play().catch(() => {}); }); // iframe 重新加载 const iframe = document.querySelector('.iframe-box iframe'); if (iframe) { iframe.addEventListener('load', function() { console.log('🔄 iframe 重新加载'); setTimeout(() => { video = findVideo(); if (video) console.log('✅ 视频重新捕获成功'); }, 1000); }); } // ---- 自动点击下一节 ---- setInterval(() => { clickNextButton(); }, CHECK_INTERVAL); setTimeout(clickNextButton, 2000); console.log(`🎯 所有功能已启动(后台伪装 + 强制播放 + 每 ${CHECK_INTERVAL/1000} 秒检测下一节)`); } // 启动 if (document.readyState === 'complete') { setTimeout(init, 1500); } else { window.addEventListener('load', () => setTimeout(init, 1500)); } })();