// ==UserScript== // @name 国家开放大学实验学院/全网办/乡村振兴学院【15倍】自动刷视频 // @namespace http://xczxzdbf.moodle.qwbx.ouchn.cn // @version 2.0.0 // @description 国开视频自动播放,15倍速,不答题不考试 // @author Your Name // @match *://xczxzdbf.moodle.qwbx.ouchn.cn/* // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // ========== 原有核心变量(保留原版逻辑) ========== let hasPlayed = false; let playbackRate = 15; // 默认15倍速(和原版一致) let isEnable = true; // 脚本总开关 // ========== 主函数(原版逻辑不变,增加开关判断) ========== function main() { // 总开关关闭则直接退出 if (!isEnable) return; if (isVideoPage()) { console.log('检测到视频页面,开始自动播放...'); autoPlayVideo(); } else { console.log('这不是一个视频播放页面。'); } } // 判断是否为视频播放页面(原版不变) function isVideoPage() { return document.querySelector('video') !== null; } // 自动播放视频(原版逻辑完全保留) function autoPlayVideo() { const video = document.querySelector('video'); if (video) { // 同步面板选择的倍速 video.playbackRate = playbackRate; if (video.paused && !hasPlayed) { video.play().then(() => { console.log('视频开始播放...'); setupVideoListeners(video); autoClickPlayButton(); }).catch(err => { console.error('自动播放失败:', err); }); } else if (!hasPlayed) { console.log('视频已在播放...'); setupVideoListeners(video); } else { console.log('视频已经播放完毕,不再重复播放。'); if (video) { video.removeEventListener('ended', onVideoEnded); video.removeEventListener('play', onVideoPlay); video.removeEventListener('pause', onVideoPause); } } } else { console.log('未找到视频元素。'); } } // 设置视频事件监听器(原版不变) function setupVideoListeners(video) { video.addEventListener('ended', onVideoEnded); function onVideoEnded() { console.log('视频播放结束...'); markVideoAsCompleted(); hasPlayed = true; video.removeEventListener('ended', onVideoEnded); video.removeEventListener('play', onVideoPlay); video.removeEventListener('pause', onVideoPause); } video.addEventListener('play', onVideoPlay); function onVideoPlay() { console.log('视频播放中...'); simulateWatchingBehavior(); } video.addEventListener('pause', onVideoPause); function onVideoPause() { console.log('视频暂停...'); // 开关开启时才自动续播 if (!hasPlayed && isEnable) { setTimeout(() => { if (!video.paused) { console.log('视频已恢复播放...'); } else { console.log('尝试恢复视频播放...'); video.play().catch(err => { console.error('恢复播放失败:', err); }); } }, 5000); } } } // 自动点击播放按钮(原版不变) function autoClickPlayButton() { console.log('尝试自动点击播放按钮...'); const playButton = document.querySelector('button[data-type="play"]'); if (playButton) { playButton.click(); console.log('播放按钮已点击'); } else { console.log('未找到播放按钮'); } } // 模拟观看行为(原版预留) function simulateWatchingBehavior() { console.log('模拟观看行为...'); } // 标记视频完成(原版预留) function markVideoAsCompleted() { console.log('标记视频为已完成...'); } // ========== 新增:可视化控制面板 + 样式 + 说明文本 ========== function createControlPanel() { // 面板容器样式 const panel = document.createElement('div'); panel.id = 'videoAutoPlayPanel'; panel.style.cssText = ` position: fixed; bottom: 25px; right: 25px; width: 290px; background: #ffffff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 2px 12px rgba(0,0,0,0.15); padding: 15px; z-index: 999999; font-family: "Microsoft Yahei", sans-serif; font-size: 14px; color: #333; user-select: none; `; // 面板标题 const title = document.createElement('div'); title.style.cssText = ` font-size: 16px; font-weight: bold; text-align: center; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px dashed #ccc; `; title.innerText = '国开视频自动刷课控制面板'; panel.appendChild(title); // 1. 总开关区域 const switchBox = document.createElement('div'); switchBox.style.cssText = 'margin: 10px 0; display: flex; align-items: center; gap: 10px;'; const switchText = document.createElement('span'); switchText.innerText = '脚本状态:'; const switchBtn = document.createElement('button'); switchBtn.id = 'mainSwitchBtn'; switchBtn.style.cssText = ` padding: 4px 12px; border: none; border-radius: 4px; background: #409eff; color: #fff; cursor: pointer; `; switchBtn.innerText = '已开启'; switchBtn.onclick = function() { isEnable = !isEnable; if (isEnable) { this.innerText = '已开启'; this.style.background = '#409eff'; main(); // 开启后立即执行 } else { this.innerText = '已关闭'; this.style.background = '#999'; } }; switchBox.appendChild(switchText); switchBox.appendChild(switchBtn); panel.appendChild(switchBox); // 2. 倍速选择区域 const rateBox = document.createElement('div'); rateBox.style.cssText = 'margin: 10px 0; display: flex; align-items: center; gap: 10px;'; const rateText = document.createElement('span'); rateText.innerText = '播放倍速:'; const rateSelect = document.createElement('select'); rateSelect.id = 'rateSelect'; rateSelect.style.cssText = 'padding: 3px 6px; border: 1px solid #ccc; border-radius: 4px;'; // 倍速选项(保留原版15倍为主) const rateList = [ {val: 1, text: '1倍'}, {val: 2, text: '2倍'}, {val: 5, text: '5倍'}, {val: 10, text: '10倍'}, {val: 15, text: '15倍(默认)'} ]; rateList.forEach(item => { const opt = document.createElement('option'); opt.value = item.val; opt.innerText = item.text; if (item.val === 15) opt.selected = true; rateSelect.appendChild(opt); }); // 倍速切换事件 rateSelect.onchange = function() { playbackRate = Number(this.value); const video = document.querySelector('video'); if (video) video.playbackRate = playbackRate; }; rateBox.appendChild(rateText); rateBox.appendChild(rateSelect); panel.appendChild(rateBox); // 3. 重置按钮 const resetBox = document.createElement('div'); resetBox.style.cssText = 'margin: 10px 0;'; const resetBtn = document.createElement('button'); resetBtn.style.cssText = ` width: 100%; padding: 5px; border: none; border-radius: 4px; background: #67c23a; color: #fff; cursor: pointer; `; resetBtn.innerText = '重置播放状态(重新刷课)'; resetBtn.onclick = function() { hasPlayed = false; alert('状态已重置,将重新开始检测播放!'); main(); }; resetBox.appendChild(resetBtn); panel.appendChild(resetBox); // 分割线 const line = document.createElement('div'); line.style.cssText = 'height: 1px; background: #eee; margin: 15px 0;'; panel.appendChild(line); // 说明文字1 const tip1 = document.createElement('div'); tip1.style.cssText = 'margin: 6px 0; line-height: 1.5;'; tip1.innerText = '1、本脚本仅适用于处理视频;'; panel.appendChild(tip1); // 说明文字2(群号:高亮标亮 红色字体+加粗) const tip2 = document.createElement('div'); tip2.style.cssText = 'margin: 6px 0; line-height: 1.5; color: #e53935; font-weight: bold;'; tip2.innerText = '2、Q群一:949193546 群二:756253160'; panel.appendChild(tip2); // 说明文字3 const tip3 = document.createElement('div'); tip3.style.cssText = 'margin: 6px 0; line-height: 1.5;'; tip3.innerText = '3、个人或机构如需处理答题、考试等联系群主;'; panel.appendChild(tip3); // 将面板加入页面 document.body.appendChild(panel); } // ========== 页面加载完成后启动 ========== window.addEventListener('load', function() { createControlPanel(); // 先创建控制面板 main(); // 再启动原版自动播放逻辑 }); })();