// ==ScriptCat== // @name 中国民政人才网络学院-学习体验优化 // @namespace https://scriptcat.org/ // @version 1.1 // @description 仅优化学习界面交互,防非人为暂停,无违规自动操作 // @author 合规优化 // @match *://*/*minzheng*/*study* // @match *://*/*mzrc*/*course* // @grant GM_addStyle // @grant GM_registerMenuCommand // ==/ScriptCat== (function() { 'use strict'; // 1. 全局样式优化(提升视觉舒适度) GM_addStyle(` /* 优化整体字体和行间距 */ body { font-size: 14px !important; line-height: 1.6 !important; } /* 固定课程目录面板 */ .course-catalog-panel { position: sticky !important; top: 20px !important; z-index: 999 !important; } /* 倍速按钮样式 */ .speed-btn-group { position: fixed; bottom: 80px; right: 20px; z-index: 9999; background: #fff; padding: 8px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); } .speed-btn { padding: 4px 8px; margin: 0 2px; border: 1px solid #ccc; border-radius: 2px; cursor: pointer; background: #f5f5f5; } .speed-btn.active { background: #1890ff; color: #fff; border-color: #1890ff; } /* 快捷返回按钮 */ .back-to-course-list { position: fixed; top: 20px; left: 20px; z-index: 9999; padding: 6px 12px; background: #1890ff; color: #fff; border-radius: 4px; cursor: pointer; text-decoration: none; } `); // 2. 添加倍速播放功能(仅针对video标签) function initSpeedControl() { // 等待视频元素加载完成 const videoObserver = new MutationObserver((mutations) => { const video = document.querySelector('video'); if (video && !document.querySelector('.speed-btn-group')) { // 创建倍速按钮组 const speedGroup = document.createElement('div'); speedGroup.className = 'speed-btn-group'; speedGroup.innerHTML = ` 播放倍速: `; document.body.appendChild(speedGroup); // 绑定倍速点击事件 speedGroup.querySelectorAll('.speed-btn').forEach(btn => { btn.addEventListener('click', (e) => { const speed = parseFloat(e.target.dataset.speed); video.playbackRate = speed; // 切换激活状态 speedGroup.querySelectorAll('.speed-btn').forEach(b => b.classList.remove('active')); e.target.classList.add('active'); }); }); videoObserver.disconnect(); } }); videoObserver.observe(document.body, { childList: true, subtree: true }); } // 3. 添加返回课程列表快捷按钮 function addBackButton() { if (document.querySelector('.back-to-course-list')) return; const backBtn = document.createElement('a'); backBtn.className = 'back-to-course-list'; backBtn.textContent = '返回课程列表'; // 适配平台课程列表路径(需根据实际页面调整href) backBtn.href = window.location.href.split('/course/')[0] + '/course/list'; backBtn.target = '_self'; document.body.appendChild(backBtn); } // 4. 新增:防非人为暂停(仅恢复意外暂停,保留用户手动暂停控制权) function initAntiUnexpectedPause() { let isUserPaused = false; // 标记是否是用户主动暂停 const checkInterval = 3000; // 每3秒检测一次(模拟人工观察频率) // 监听视频元素加载 const videoObserver = new MutationObserver((mutations) => { const video = document.querySelector('video'); if (video) { // 监听用户手动暂停/播放事件 video.addEventListener('pause', () => { // 判断是否是用户主动暂停(通过点击事件标记) isUserPaused = true; }); video.addEventListener('play', () => { isUserPaused = false; // 用户主动播放,重置标记 }); // 监听用户点击暂停按钮的行为(兼容平台自定义播放控件) document.addEventListener('click', (e) => { if (e.target.closest('.video-pause-btn, .play-control, .pause-btn')) { isUserPaused = true; } if (e.target.closest('.video-play-btn, .play-control.play')) { isUserPaused = false; } }); // 定时检测并恢复非人为暂停 setInterval(() => { // 仅在以下条件满足时恢复播放: // 1. 视频已加载 2. 视频处于暂停状态 3. 不是用户主动暂停 4. 视频未播放完成 if (video.readyState >= 2 && video.paused && !isUserPaused && video.currentTime < video.duration - 1) { video.play().catch(err => { // 捕获播放失败(如浏览器需要用户交互),不做强制操作 console.log('需手动点击播放视频:', err); }); } }, checkInterval); videoObserver.disconnect(); } }); videoObserver.observe(document.body, { childList: true, subtree: true }); } // 5. 页面加载完成后初始化功能 window.addEventListener('load', () => { initSpeedControl(); addBackButton(); initAntiUnexpectedPause(); // 初始化防意外暂停功能 // 注册脚本猫菜单:恢复默认样式/关闭防暂停 GM_registerMenuCommand('恢复默认页面样式', () => { location.reload(); }); }); })();