# 浙江水利刷课脚本 **Repository Path**: tuziang/zhejiang-shuili ## Basic Information - **Project Name**: 浙江水利刷课脚本 - **Description**: 浙江水利刷课脚本,支持视频自动播放、防止暂停、自动切换、页面防休眠 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-24 - **Last Updated**: 2026-02-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 浙江水利刷课脚本 ### 脚本介绍 该油猴脚本用于 浙江水利 的辅助看课,使用JavaScript编写,适配网址:https://sgpt.zjwater.com/ **脚本功能如下:** 1. 视频自动播放 2. 防止视频暂停 3. 自动切换下一课 4. 页面防休眠 **脚本安装地址:** 暂时下架 如果不会安装脚本,请按照下面安装教程来操作。 ### 代学服务 **如需代学,请联系客服,支持闲鱼交易。** - 微信联系:yizhituziang ![https://jiaobenmiao.com/img/weixin.jpg](https://jiaobenmiao.com/img/weixin.jpg) - QQ联系:2422270452 ![https://jiaobenmiao.com/img/qq.jpg](https://jiaobenmiao.com/img/qq.jpg) ### 安装教程 #### 1.安装浏览器扩展插件 首先需要给我们的浏览器安装上脚本猫插件,这是运行所有用户脚本的基础,如果浏览器已经安装过了脚本猫或者油猴插件,那么可以跳过这一步。推荐使用edge浏览器,安装插件更方便。 浏览器打开网址:[https://docs.scriptcat.org/](https://docs.scriptcat.org/) 这里用edge浏览器作为示范,点击 **"添加到Edge浏览器"** ![image-20250916183549234](https://jiaobenmiao.com/articleimg/image-20250916183549234.png) 接着点击 **"获取"** ![image-20250916183818025](https://jiaobenmiao.com/articleimg/image-20250916183818025.png) 在右上角弹出的窗口,点击 **"添加扩展"** ![image-20250916183841569](https://jiaobenmiao.com/articleimg/image-20250916183841569.png) 等待几秒钟,会提示已经安装好脚本猫插件了。 ![image-20250916183906107](https://jiaobenmiao.com/articleimg/image-20250916183906107.png) #### 2.安装刷课脚本 打开脚本安装地址后,在页面点击 **"安装脚本"** 按钮,接着在弹出的窗口点击 **"安装"** ,之后就会提示"安装成功"。 #### 3.体验脚本功能 安装脚本后,需要重新进入学习站点,如果之前已经打开课程学习页面,那么需要刷新页面后脚本才会生效。 ### 核心代码 ```js (function() { 'use strict'; const settings = { videoCheckInterval: 1500, lessonCheckInterval: 5000, autoMute: true, autoPlay: true, preventPause: true }; console.log('浙江水利刷课脚本已加载'); function preventVisibilityDetection() { const originalAddEventListener = EventTarget.prototype.addEventListener; EventTarget.prototype.addEventListener = function(type, listener, options) { if (type === 'visibilitychange' || type === 'blur' || type === 'focusout') { console.log('拦截了 ' + type + ' 事件'); return; } return originalAddEventListener.call(this, type, listener, options); }; Object.defineProperty(document, 'hidden', { value: false, writable: false, configurable: false, enumerable: true }); Object.defineProperty(document, 'visibilityState', { value: 'visible', writable: false, configurable: false, enumerable: true }); window.onblur = function() { return false; }; window.onfocusout = function() { return false; }; } function findAndPlayVideo() { const videos = document.getElementsByTagName('video'); for (let i = 0; i < videos.length; i++) { const video = videos[i]; if (settings.autoMute && !video.muted) { video.muted = true; video.volume = 0; } if (settings.autoPlay && video.paused) { video.play().then(function() { console.log('视频 ' + (i + 1) + ' 播放成功'); }).catch(function(error) { console.log('视频播放失败: ' + error); simulateUserClick(video); }); } if (video.ended) { console.log('视频播放完毕,准备切换下一课'); goToNextLesson(); } } } function simulateUserClick(element) { const clickEvent = new MouseEvent('click', { view: window, bubbles: true, cancelable: true }); element.dispatchEvent(clickEvent); } function goToNextLesson() { const nextLessonSelectors = [ 'a:contains("下一课")', 'button:contains("下一课")', '.next-lesson-btn', '#nextLesson', '[class*="next"]', '[title*="下一课"]', '.lesson-list li:not(.completed) a' ]; for (let s = 0; s < nextLessonSelectors.length; s++) { try { let elements; if (nextLessonSelectors[s].indexOf(':contains') !== -1) { const text = nextLessonSelectors[s].match(/:contains\("(.*)"\)/)[1]; elements = Array.from(document.querySelectorAll('a, button')).filter(function(el) { return el.innerText && el.innerText.indexOf(text) !== -1; }); } else { elements = document.querySelectorAll(nextLessonSelectors[s]); } if (elements.length > 0) { elements[0].click(); console.log('成功点击下一课'); return; } } catch (e) { continue; } } const allLinks = document.querySelectorAll('a'); for (let i = 0; i < allLinks.length; i++) { const link = allLinks[i]; if (link.innerText && (link.innerText.indexOf('下一课') !== -1 || link.innerText.indexOf('继续') !== -1)) { link.click(); console.log('通过文本匹配找到了下一课'); return; } } } function preventVideoPause() { const videos = document.getElementsByTagName('video'); for (let i = 0; i < videos.length; i++) { const video = videos[i]; video.addEventListener('pause', function(e) { if (!video.ended) { console.log('检测到暂停,尝试继续播放'); e.preventDefault(); video.play(); } }); } } function simulateUserActivity() { document.body.dispatchEvent(new MouseEvent('mousemove', { view: window, bubbles: true, cancelable: true })); document.body.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true, cancelable: true })); } function mainLoop() { findAndPlayVideo(); preventVideoPause(); } function init() { preventVisibilityDetection(); setTimeout(function() { findAndPlayVideo(); }, 2000); setInterval(mainLoop, settings.videoCheckInterval); setInterval(simulateUserActivity, 30000); console.log('浙江水利刷课脚本初始化完成'); } if (document.readyState === 'complete' || document.readyState === 'interactive') { setTimeout(init, 1000); } else { document.addEventListener('DOMContentLoaded', init); } })(); ```