// ==UserScript== // @name bw-learn-tool // @namespace http://tampermonkey.net/ // @version 1.1.5 // @description 自动静音、自动播放、自动下一节 // @author jinxhcn // @match *://learn.baowugroup.com/* // @grant unsafeWindow // @license MIT // @run-at document-idle // ==/UserScript== (function() { 'use strict'; console.log('✅ 宝武学习助手 v1.1.5'); const $max = 10; const $chk = 2000; let $st = { $hcn: false, $pa: 0, $lvs: '', $wfp: false, $tm: null, $uf: false }; function $gv() { return document.querySelector('#xg-video video'); } function $hns() { const current = document.querySelector('.el-tree-node.is-current'); if (!current) return false; let node = current; while (node) { let next = node.nextElementSibling; while (next) { if (next.classList.contains('el-tree-node')) return true; next = next.nextElementSibling; } node = node.parentElement?.closest?.('.el-tree-node'); } return false; } function $cns() { const candidates = ['播放下一节', '下一节']; for (const text of candidates) { const btns = document.querySelectorAll('button'); for (const btn of btns) { if (btn.offsetParent !== null && (btn.innerText.trim() === text || btn.innerText.includes(text))) { btn.click(); console.log('✅ 已点击“下一节”'); return true; } } } const hints = document.querySelectorAll('*'); for (const el of hints) { if (el.offsetParent !== null && el.innerText?.trim() === '本节播放结束, 是否继续播放?') { const container = el.closest('.play-chapter') || el.parentElement; if (container) { const btn = container.querySelector('button'); if (btn && btn.offsetParent !== null) { btn.click(); console.log('✅ 已点击“下一节”(通过结束提示)'); return true; } } break; } } const primaryBtns = document.querySelectorAll('.el-button--primary'); for (const btn of primaryBtns) { if (btn.offsetParent !== null && btn.innerText.includes('下一节')) { btn.click(); console.log('✅ 已点击“下一节”(Primary 按钮)'); return true; } } console.warn('⚠️ 未找到“下一节”按钮'); return false; } function $pcv(video) { if (!video) return false; if (video.ended || !video.paused) return false; if ($st.$pa >= $max) { console.warn(`⏸️ 已尝试 ${$max} 次,暂停播放尝试`); return false; } $st.$pa++; if (!video.muted) { video.muted = true; console.log('🔇 已静音'); } const playBtn = document.querySelector('.xgplayer-start'); if (playBtn && playBtn.offsetParent !== null) { playBtn.click(); console.log(`▶️ 点击中央播放按钮 (${$st.$pa}/${$max})`); return true; } const icon = document.querySelector('.xgplayer-play .xgplayer-icon'); if (icon && icon.offsetParent !== null) { icon.click(); console.log(`▶️ 点击控制栏播放图标 (${$st.$pa}/${$max})`); return true; } const container = document.querySelector('#xg-video, .xgplayer'); if (container) { container.click(); console.log(`▶️ 点击视频画面区域 (${$st.$pa}/${$max})`); return true; } video.play().catch(() => {}); console.log(`▶️ 调用原生 video.play() (${$st.$pa}/${$max})`); return true; } function $rps() { clearTimeout($st.$tm); $st.$pa = 0; $st.$hcn = false; $st.$wfp = true; $st.$uf = false; $st.$tm = setTimeout(() => { $st.$wfp = false; if (!document.hidden) { const video = $gv(); if (video) $pcv(video); } }, 300); } function $ml() { const video = $gv(); if (video) { const currentSrc = video.currentSrc || video.src; if (currentSrc && currentSrc !== $st.$lvs) { $st.$lvs = currentSrc; $rps(); } } if (video && !video.paused) { if ($st.$wfp) { clearTimeout($st.$tm); $st.$wfp = false; } if ($st.$pa > 0) { $st.$pa = 0; } if (!$st.$uf) { const startBtn = document.querySelector('.xgplayer-start'); if (startBtn && startBtn.offsetParent !== null) { startBtn.classList.add('hide'); console.log('🎯 隐藏中央按钮'); } const overlay = document.querySelector('.video-overlay'); if (overlay && overlay.offsetParent !== null) { overlay.style.display = 'none'; console.log('🎯 隐藏视频覆盖层'); } $st.$uf = true; } return; } if (video && video.ended) { if ($hns() && !$st.$hcn) { if ($cns()) { $st.$hcn = true; } } else if (!$hns()) { console.log('🏁 所有课程已播放完毕'); } return; } if (video && video.paused && !$st.$wfp) { const overlay = document.querySelector('.video-overlay'); if (overlay) { overlay.style.display = ''; console.log('🔄 恢复视频覆盖层显示 (暂停状态)'); } $st.$uf = false; $pcv(video); return; } if (!$st.$hcn) { const hints = document.querySelectorAll('*'); for (const el of hints) { if (el.offsetParent !== null && el.innerText?.trim() === '本节播放结束, 是否继续播放?') { if ($hns()) { if ($cns()) { $st.$hcn = true; } } break; } } } } setInterval($ml, $chk); document.addEventListener('visibilitychange', () => { if (!document.hidden) { if ($st.$wfp) { clearTimeout($st.$tm); $st.$wfp = false; const video = $gv(); if (video) $pcv(video); } setTimeout($ml, 500); } }); })();