// ==UserScript== // @name 科研诚信培训系统/诚信学堂/wanfangdata // @namespace http://tampermonkey.net/ // @version 1.1 // @description 当前视频播放完成后自动切换到下一节并开始播放 // @author Erifil // @match https://cx.wanfangdata.com.cn/* // @icon https://www.google.com/s2/favicons?sz=64&domain=wanfangdata.com.cn // @grant none // @license All Rights Reserved // ==/UserScript== (function () { 'use strict'; let switching = false; function clickPlayButton() { const playButton = document.querySelector('.prism-big-play-btn'); if (playButton) { console.log('[自动播放] 点击播放按钮'); playButton.click(); return true; } return false; } function waitAndPlay() { let attempts = 0; const maxAttempts = 20; const timer = setInterval(() => { attempts++; if (clickPlayButton() || attempts >= maxAttempts) { clearInterval(timer); if (attempts >= maxAttempts) { console.warn('[自动播放] 未找到播放按钮'); } // 页面完成切换后,允许检测下一条视频的进度。 setTimeout(() => { switching = false; }, 3000); } }, 1000); } function checkProgress() { if (switching) { return; } const progressElement = document.querySelector('.el-progress-bar__innerText'); if (!progressElement) { return; } const progress = progressElement.textContent.trim(); if (progress === '100%') { const nextButton = document.querySelector('span.next'); if (!nextButton) { console.warn('[自动播放] 当前视频已完成,未找到下一节按钮'); return; } switching = true; console.log('[自动播放] 当前视频已完成,切换至下一节'); nextButton.click(); // 等待下一节页面和播放器加载,再点击播放。 setTimeout(waitAndPlay, 1500); } } setInterval(checkProgress, 1000); })();