// ==UserScript== // @name 广西干部网络学院-课程助手 // @namespace http://tampermonkey.net/gxela_template_广西干部网络学院-课程助手 // @version 1.0.0 // @description 广西干部网络学院学习助手-可帮助学习 // @author ssss // @match *://www.gxela.gov.cn/* // @match *://gxela.gov.cn/* // @grant unsafeWindow // @grant GM_getValue // @grant GM_setValue // @grant GM_info // @grant GM_addStyle // @antifeature ads 有弹窗广告,介绍完全自动化软件 // @antifeature payment 脚本基础功能使用免费,但需要使用完全自动化软件时,可能收费 // ==/UserScript== const CONFIG = { siteName: 'gxela_广西教育平台', // 网站名(日志/弹窗用) // —— 【必改】网站唯一 ID,用于官网文档跳转,换站换新值 —— webId: '3ed13579a43472299a123aea', // —— 【必改】BroadcastChannel 频道名,换站换新值(防多站点串台)—— channel: 'channel-gxela', // 脚本启动时弹窗提示文字 swFireText: '请在"学习中心-我的班级"页面使用脚本,点击控制台"开始运行"按钮后,自动学习列表第一个课程视频。', // 控制面板顶部提示文字(基础版状态) baseText: '建议下载软件使用!全自动学习所有未完成视频', // 控制面板顶部提示文字(VIP/已验证状态) vipText: '全自动建议下载客户端使用!', // VIP 高级功能按钮文字 vipBtnText: '高级功能-全自动挂机', // 【升级弹窗】当前脚本功能列表(左栏) scriptFeatures: [ '自动学习班级课程视频', '防暂停', '自动静音播放', '仅限单页面使用', ], // 【升级弹窗】客户端软件功能列表(右栏) softwareFeatures: [ '输入账号密码即可全自动', '全自动完成所有未完成课程 + 考试', '支持批量多账号同时学习', ], // —— 【下载/购买链接配置】换站时按需替换 —— // 阿里云盘下载链接 aliLink: 'https://www.alipan.com/s/wViqbLvgSF8', // 直链下载地址(备用) directLink: 'https://zzzzzzys.lanzouu.com/b00zxor42h', // 授权码购买链接(显示在控制台 + 购买弹窗里;需要多个链接时往数组里追加) link: [ 'https://68n.cn/IJ8QB', ], // 备用网址列表(官网打不开时使用,升级弹窗底部展示) web_list: [ { name: '备用地址0', url: 'https://www.zzzzzzys.com/' }, { name: '备用地址1', url: 'https://zzzzzzys.lovestoblog.com/' }, { name: '备用地址2', url: 'https://zzzzzzys.us.kg/' }, { name: '备用地址3', url: 'https://zzysdocs.dpdns.org/' }, { name: '备用地址4', url: 'https://zzzzzzys.dpdns.org/' }, { name: '备用地址5', url: 'https://zzzzzzys.kesug.com/' }, { name: '备用地址6', url: 'https://zzysdocs.great-site.net/' }, ], // 官网文档链接(自动拼接 webId,一般不用改) docLink: null, // 下方自动赋值 // 控制台只在顶层窗口创建(避免 iframe 页面重复弹出多个面板) topFrameOnly: true, }; CONFIG.docLink = CONFIG.web_list[0].url + '?webId=' + CONFIG.webId; /* ============================================================ * ② SiteTask 功能区【每个新网站必改】 * ------------------------------------------------------------ * 对应原 Course 类的框架接线部分(init/loadVIPStatus/runVIP/finish/sendMsg) * + 功能入口 run()。run() 里的站点逻辑是唯一需要大改的地方。 * 启动方式:手动点击控制台"开始运行-自动化挂机"按钮(无自动开始)。 * 框架能力: * this.panel —— 控制台(setTip/showError/handleVerify) * MiniSwal.fire —— 弹窗(用法同 Swal.fire,返回 {isConfirmed,isDismissed,dismiss}, * 关闭原因用 MiniSwal.DismissReason) * Utils.showUpgradeAlert() —— 广告升级弹窗 * this.channel / sendMsg(msg) —— BroadcastChannel 多标签广播 * this.VIP —— 是否已验证授权 * ============================================================ */ /* —— 【功能配置】广西干部网络学院(gxela) 站点选择器 —— * "我的班级"课程列表实测 DOM(Vite + Vue3 + Element Plus): * .lesson-list-container * └ .lesson-list-item ← 课程条目(每课一条,DOM 顺序即列表顺序) * ├ .el-progress[aria-valuenow] ← 学习进度(0-100) * └ .lesson-list-item__button > .lesson-button > button ← 启动按钮(文本:未开始/继续学习/已通过) * 条目本身是 div 无点击事件,必须点条目内的 button 才会进入课程。 * 页面结构如有出入,只改这里。 */ const SITE = { // 课程列表条目选择器:实测值优先,首个命中即用 listSelectors: [ '.lesson-list-container .lesson-list-item', ], // 条目内的启动按钮(依次尝试:实测按钮 → 条目内任意按钮) buttonSelector: '.lesson-list-item__button button, .lesson-button button', // 点击列表项后等待播放页 video 出现的超时(毫秒) videoTimeout: 20000, }; /* —— 【通用框架】日志工具 —— * 功能区直接调用 Logger.log('...') / warn / error,输出带 [HH:MM:SS] 时间戳。 */ class Logger { static stamp() { const d = new Date(); const p = n => String(n).padStart(2, '0'); return `[${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}]`; } static log(...args) { console.log(this.stamp(), ...args); } static warn(...args) { console.warn(this.stamp(), ...args); } static error(...args) { console.error(this.stamp(), ...args); } } class SiteTask { constructor(panel) { this.panel = panel; this.channel = new BroadcastChannel(CONFIG.channel); this.VIP = false; this.running = false; this.url = null; this.init(); } init() { // 授权码验证回调(纯本地):validateCode 只弹升级广告,url 恒为空 this.panel.setOnVerifyCallback(async (data) => { this.url = await Utils.validateCode(data); if (this.url) { this.panel.setTip(CONFIG.vipText); this.VIP = true; return true; } }); // 控制台"开始运行"按钮回调 this.panel.setOnBegin(() => { if (!this.running) { this.running = true; console.log('运行时:', this.VIP); this.run().then(r => { this.running = false; // 提前返回(未找到列表/未检测到视频)时 run() 内部已调用 stopAutomation; // 正常播放中保持"运行中"状态,ended→finish() 时再恢复按钮 }).catch(e => { this.running = false; console.error('运行异常:', e); this.panel.stopAutomation(); }); } }); // VIP 高级功能按钮回调 this.panel.setOnVIP(async () => { if (!this.url) { await this.panel.handleVerify(); } await this.runVIP(); }); this.loadVIPStatus(); // 启动提示弹窗:仅作提示,不自动开始;手动点击控制台"开始运行"按钮才启动 try { MiniSwal.fire({ title: '提示', text: CONFIG.swFireText, icon: 'info', timer: 5000, confirmButtonText: '确定', timerProgressBar: true, }); } catch (e) { console.error(e); } } loadVIPStatus() { if (Utils.loadStatus()) { this.panel.setTip(CONFIG.vipText); this.VIP = true; } else { this.panel.setTip(CONFIG.baseText); this.VIP = false; } console.log('VIP:', this.VIP); } async runVIP() { try { Utils.showUpgradeAlert(); } catch (error) { console.error(error); MiniSwal.fire({ title: '高级功能执行失败!', text: '若一直失败,请联系进行售后处理!', icon: 'error', confirmButtonText: '确定', allowOutsideClick: false, willClose: () => { console.log(' 用户确认错误,脚本已停止'); } }); } } finish() { // 学习完成:统一提示文案(对所有用户一致,不区分版本、不含任何数量/权限相关字样) this.sendMsg('finish'); this.panel.stopAutomation(); // 播放终态:恢复"开始运行"按钮与计时器 MiniSwal.fire({ title: '学习完成!', text: '本节内容学习完成。', icon: 'success', confirmButtonText: '确定', timer: 5000, timerProgressBar: true, }); } sendMsg(msg) { // 复用构造函数里创建的 channel 实例广播(原版每次 new 会有频道名转换问题,已修正) this.channel.postMessage(msg); } async run() { // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ // ★【功能区代码写在这里】★ 换网站时只改本方法 // // 学习策略(gxela·广西干部网络学院): // 1. 用户在"学习中心-我的班级"页面手动点击"开始运行" // 2. 自动点击课程列表第一项的启动按钮进入播放页(当前页已有视频则直接播放) // 3. 静音自动播放 + 防暂停 // 4. 播完本节即结束(单节模式,不连播下一项),完成提示对所有用户一致 // 页面结构如有出入:改上方 SITE.listSelectors / SITE.buttonSelector 选择器即可。 // ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ // 第一步:当前页面已有视频 → 直接进入播放流程(已在播放页) let video = document.querySelector('video'); // 第二步:无视频 → 视为在列表页,点击列表第一项进入播放页 if (!video) { Logger.log('当前页无视频,尝试从课程列表进入第一项...'); const firstItem = this.findFirstListItem(); if (!firstItem) { MiniSwal.fire({ title: '提示', text: '未找到课程列表,请进入"学习中心-我的班级"页面后重新点击开始运行。', icon: 'info', confirmButtonText: '确定', }); this.panel.stopAutomation(); // 失败终态:恢复按钮,允许用户切页后重试 return; } Logger.log('进入列表第一项:', (firstItem.textContent || '').trim().replace(/\s+/g, ' ').slice(0, 40)); // .lesson-list-item 是 div 本身无点击事件,实际点击条目内的启动按钮; // 按钮未渲染出来时兜底点条目本身 const startBtn = firstItem.querySelector(SITE.buttonSelector) || firstItem; startBtn.click(); video = await Utils.getStudyNode('video', 'node', SITE.videoTimeout); if (!video) { MiniSwal.fire({ title: '提示', text: '已进入课程但未检测到视频,请确认课程内容后重新点击开始运行。', icon: 'info', confirmButtonText: '确定', }); this.panel.stopAutomation(); // 失败终态:恢复按钮(20 秒等不到视频多为新标签打开/页面未跳转) return; } } video.volume = 0; video.muted = true; if (this._preventPauseHandler) { video.removeEventListener('pause', this._preventPauseHandler); } // 防暂停:检测到 pause 事件后 500ms 自动恢复播放 let pauseTimeout = null; this._preventPauseHandler = async () => { if (video.ended) return; if (pauseTimeout) clearTimeout(pauseTimeout); pauseTimeout = setTimeout(async () => { console.log('检测到视频暂停,自动恢复播放...'); video.volume = 0; video.muted = true; try { await video.play(); } catch (e) { console.error('恢复播放失败:', e); } }, 500); }; video.addEventListener('pause', this._preventPauseHandler); // 播完本节即结束:单节模式,不查找/不连播下一项 video.addEventListener('ended', () => { Logger.log('本节学习完成,脚本结束'); this.finish(); }, { once: true }); try { await video.play(); Logger.log('视频开始自动播放'); } catch (e) { console.error('自动播放失败:', e); // 浏览器拦截自动播放时引导一次手动点击,之后由防暂停逻辑接管 MiniSwal.fire({ title: '提示', text: '浏览器拦截了自动播放,请点击一次视频播放按钮,脚本会自动接管后续过程。', icon: 'info', confirmButtonText: '确定', }); } } /** * 在候选选择器中查找第一个可见的课程列表条目 * (排除导航/页头/页脚里的链接,避免误点菜单) */ findFirstListItem() { for (const sel of SITE.listSelectors) { let nodes; try { nodes = document.querySelectorAll(sel); } catch (e) { continue; } for (const n of nodes) { if (n.closest('header, nav, footer, .nav, .menu, .header, .footer, .top, .sidebar')) continue; const rect = n.getBoundingClientRect(); if (rect.width > 0 && rect.height > 0) return n; } } return null; } } /* ============================================================ * ③ 通用框架区【无需改动】 * ============================================================ */ // 样式注入:优先 GM_addStyle,没有则手动插