// ==UserScript== // @name 国家食品药品安全专业技术人员培训网|使用说明:http://doc.zhanyc.cn/pages/gjsya/ // @namespace free // @version 1.0 // @description 当前是免费版本,只包含了解除视频暂停限制和评估答题功能。如需自动下一集、自动换课程、考试答题等高级功能可升级付费版本|接各类脚本开发、代挂任务,微信:zhanyc_cn 个人网站:http://doc.zhanyc.cn // @include *://*.gwypx.com.cn/* // @include *://*.nmpaied.com/* // @grant GM_addStyle // @run-at document-end // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // @antifeature payment // @license Creative Commons // ==/UserScript== (function () { let docUrl = "http://doc.zhanyc.cn/pages/gjsya/"; let yxk = { pageData: { videoTimer: null, videoEl: null, }, async init() { console.log("%c [免费版] init", "background:rgb(0,0,0);color:#fff"); yxk.addStyle(); yxk.showFloatPanel(); yxk.runByUrl(location.href); }, async runByUrl(url) { if (url.includes("/model/media.htm") || url.includes("/video_play?")) { yxk.page_video(); } else if ( url.includes("/pc/index.htm") && url.includes("assess_list") || url.includes("/pc/#/assess_list?") ) { yxk.page_assess_list(); } }, async page_video() { console.log("%c [免费版] page_video", "background:rgb(0,0,0);color:#fff"); await yxk.waitFor(() => $("video").length > 0, 1000, 60); await yxk.sleep(1000); yxk.setupVideoPanel(); yxk.pageData.videoTimer = setInterval(async () => { try { let video = yxk.getVideo(); if (!video) return; video.volume = 0; let curTime = video.currentTime; let totalTime = video.duration; let title = `进度:${curTime.toFixed(0)}/${totalTime.toFixed(0)}`; $("title").text(title); yxk.updateVideoProgress(curTime, totalTime); // 处理"是否继续学习"弹窗 let $continueBtn = yxk.findElByText($(".el-dialog__body"), "是否继续学习?"); if ($continueBtn != null) { $continueBtn.next().find("button").click(); } // 处理"实时在线学习"弹窗 let $onlineTips = yxk.findElByText( ".layui-layer-content p", "您好,本平台要求实时在线学习,点击按钮,继续学习课程。" ); if ($onlineTips != null) { $onlineTips.parents(".layui-layer").find(".layui-layer-btn0")[0].click(); } // 检查播放是否完成 if (totalTime > 0 && curTime + 5 >= totalTime) { yxk.updateFloatContent('
当前视频播放已完成
'); clearInterval(yxk.pageData.videoTimer); yxk.pageData.videoTimer = null; return; } // 如果未播放则自动播放 let isPlaying = await yxk.checkVideoPlaying(); if (!isPlaying) { video.volume = 0; setTimeout(() => { video.play(); }, 200); } } catch (e) { console.error("[免费版] 视频定时器出错", e); } }, 2000); }, async page_assess_list() { console.log("%c [免费版] page_assess_list", "background:rgb(0,0,0);color:#fff"); await yxk.waitFor(() => $(".question").length > 0); await yxk.sleep(1000); let $elArr = []; $(".question").each((i, el) => { $elArr.push($(el).find("label").eq(0)); }); for (let i = 0; i < $elArr.length; i++) { const $el = $elArr[i]; $el.click(); await yxk.sleep(100); } yxk.updateFloatContent('
评估答题已完成,请手动提交
'); await yxk.sleep(3000); yxk.findElByText($("button"), "提交").click(); await yxk.sleep(500); $("button.el-button--primary").click(); }, // ========== 视频面板 ========== setupVideoPanel() { yxk.pageData.videoEl = $("video")[0]; $("#yxkFloatContent").html(`
▶ 视频播放中
进度:0/0
`); }, updateVideoProgress(curTime, totalTime) { let $progress = $("#yxkVideoProgress"); if ($progress.length > 0) { $progress.text(`进度:${curTime.toFixed(0)}/${totalTime.toFixed(0)}`); } }, // ========== 悬浮面板 ========== showFloatPanel() { if ($("#yxkFloatPanel").length > 0) return; let panelHtml = `
脚本运行中 ×
✓ 免费版功能
• 解除视频暂停限制
• 自动评估答题
★ 付费版功能
• 全自动下一集 / 自动换课程
• 考试自动答题
• 评估自动答题
• 全自动无人值守
• 防掉线保活
如需使用全功能版本,请通过地址安装付费版本购买授权后可使用
点击前往付费版本(一次付费、永久使用、免费维护)
接各类脚本开发、代挂、网站小程序开发工作
微信:zhanyc_cn
`; $("body").append(panelHtml); $("#yxkFloatClose").click(function () { $("#yxkFloatPanel").hide(); }); }, updateFloatContent(html) { $("#yxkFloatContent").html(html).show(); }, // ========== 样式 ========== addStyle() { GM_addStyle(` #yxkFloatPanel{position:fixed;left:0;top:10px;z-index:99999;font-size:14px;color:#fff;max-width:300px} #yxkFloatHeader{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);padding:8px 12px;cursor:pointer;border-radius:0 4px 0 0;display:flex;justify-content:space-between;align-items:center;box-shadow:0 2px 10px rgba(0,0,0,0.3)} #yxkFloatTitle{font-weight:bold;font-size:14px} #yxkFloatClose{cursor:pointer;font-size:18px;line-height:1;padding:0 4px;color:#fff} #yxkFloatClose:hover{color:#ff6b6b} #yxkFloatContent{background:rgba(0,0,0,0.85);padding:10px;border-radius:0 0 4px 0;box-shadow:0 2px 10px rgba(0,0,0,0.3)} #yxkFloatContent a:hover{color:#fff} `); }, // ========== 视频方法 ========== getVideo() { return $("video")[0]; }, async checkVideoPlaying() { return new Promise((resolve) => { try { let curTime = $("video")[0].currentTime; setTimeout(() => { let time1 = $("video")[0].currentTime; let res = time1 > curTime; if (res) { setTimeout(() => { let time2 = $("video")[0].currentTime; let res2 = time2 > time1; resolve(res2); }, 100); } else { return resolve(false); } }, 100); } catch (e) { resolve(false); } }); }, // ========== 工具方法 ========== sleep(timeout) { return new Promise((resolve) => { setTimeout(() => { resolve(); }, timeout); }); }, waitFor(fun, interval = 1000, timeout = 30) { return new Promise((resolve, reject) => { let _timeOut = timeout * 1000; if (fun()) return resolve(); let index = setInterval(() => { if (timeout != -1) { _timeOut -= interval; if (_timeOut < 0) { clearInterval(index); return reject(); } } if (fun()) { clearInterval(index); return resolve(); } }, interval); }); }, findElByText(query, text, mode = "eq", visible = true) { let $el = null; $(query).each((i, el) => { if (visible && !$(el).is(":visible")) return true; if (mode == "eq" && $(el).text().trim() == text) { $el = $(el); return false; } else if (mode == "startsWith" && $(el).text().trim().startsWith(text)) { $el = $(el); return false; } else if (mode == "endsWith" && $(el).text().trim().endsWith(text)) { $el = $(el); return false; } }); return $el; }, }; // 3秒后检测是否已有付费版本在运行 setTimeout(() => { debugger if (typeof (zfk) == 'undefined') { yxk.init(); } else { console.log('skip init'); } }, 3000); })();