// ==UserScript== // @name 🍀八大员|三类人|住房城乡建设行业从业人员教育培训平台|使用说明:http://doc.zhanyc.cn/pages/bdyslr/ // @namespace free // @version 1.0 // @description 当前是免费版本,只包含了解除视频暂停限制功能。如需自动下一集、自动换课程、全自动无人值守等高级功能可升级付费版本|接各类脚本开发、代挂任务,微信:zhanyc_cn 个人网站:http://doc.zhanyc.cn // @include *://*etledu.com* // @include *://*.etledu.com/* // @include *://*.gsjtpxzx.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant window.close // @run-at document-end // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // @license MIT // ==/UserScript== (function () { let $jq = $; unsafeWindow.$jq = $; let xyDocUrl = "http://doc.zhanyc.cn/pages/bdyslr/"; let xyIsDev = true; let xyApp = { pageData: { videoTimer: null, waitTime: 0, checkTimes: 0, videoStarted: false, }, // 等待条件满足 xyWaitOf(fun, interval, timeout) { interval = interval || 1000; timeout = timeout || 30; return new Promise((resolve, reject) => { let _timeOut = timeout * 1000; try { if (fun()) return resolve(); } catch (e) { } let index = setInterval(() => { try { if (timeout != -1) { _timeOut -= interval; if (_timeOut < 0) { clearInterval(index); return reject(); } } if (fun()) { clearInterval(index); return resolve(); } } catch (e) { } }, interval); }); }, // 等待指定毫秒 xyWaitMs(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); }, // 获取视频元素 xyGetVideo() { return $("video")[0]; }, // 播放视频 xyPlayVideo() { let v = xyApp.xyGetVideo(); if (v) { v.volume = 0; setTimeout(() => { v.play(); }, 200); } }, // 获取当前播放时间 xyGetCurTime() { try { return xyApp.xyGetVideo().currentTime; } catch (e) { return 0; } }, // 获取视频总时长 xyGetTotalTime() { try { return xyApp.xyGetVideo().duration; } catch (e) { return 0; } }, // 检测视频是否在播放中 xyVideoIsPlaying() { return new Promise((resolve) => { try { let curTime = xyApp.xyGetCurTime(); setTimeout(() => { let t1 = xyApp.xyGetCurTime(); if (t1 > curTime) { setTimeout(() => { let t2 = xyApp.xyGetCurTime(); resolve(t2 > t1); }, 100); } else { resolve(false); } }, 100); } catch (e) { resolve(false); } }); }, // 检测播放是否完成 xyIsPlayDone() { try { return xyApp.xyGetTotalTime() > 0 && xyApp.xyGetCurTime() + 5 >= xyApp.xyGetTotalTime(); } catch (e) { return false; } }, // 更新悬浮面板视频状态 xyUpdateVideoStatus() { let $panel = $("#xy_free_panel"); if ($panel.length == 0) return; let curTime = xyApp.xyGetCurTime().toFixed(0); let totalTime = xyApp.xyGetTotalTime().toFixed(0); let pct = 0; if (Number(totalTime) > 0) { pct = ((Number(curTime) / Number(totalTime)) * 100).toFixed(1); } $("#xy_video_status").html(`▶ 视频播放中
进度:${curTime}s / ${totalTime}s(${pct}%)`); }, // 在悬浮面板显示提示信息 xyShowPanelTip(msg, color) { color = color || "#ff6600"; let $tip = $("#xy_panel_tip"); if ($tip.length == 0) { $("#xy_free_panel .xy_panel_body").append(`
`); $tip = $("#xy_panel_tip"); } $tip.css("background", color).text(msg).show(); }, // 创建悬浮引流面板 xyCreatePanel() { if ($("#xy_free_panel").length > 0) return; let panelHtml = `
脚本免费版 ×
🎁 如需使用全功能版本,请通过地址安装付费版本
一次付费、永久使用、免费维护
${xyDocUrl}
等待视频加载...
📄 当前版本功能:解除视频暂停限制
💼 接各类脚本开发、代挂、网站小程序开发工作
微信:zhanyc_cn
`; $("body").append(panelHtml); $("#xy_close_panel").click(function () { $("#xy_free_panel").remove(); }); }, // 点击视频学习按钮 xyClickVideoBtns() { return new Promise(async (resolve) => { let $btnArr = []; $('.btn_container .layui-btn.layui-btn-normal').each((i, el) => { $btnArr.push($(el)); }); for (let i = 0; i < $btnArr.length; i++) { $btnArr[i].click(); await xyApp.xyWaitOf(() => { return $('.btn_container .layui-btn.layui-btn-normal:visible').length == 0; }, 1000, 30); if ($('.btn_container .layui-btn.layui-btn-normal:visible').length == 0) { resolve(); break; } await xyApp.xyWaitMs(5000); } }); }, // 视频页面主逻辑 async page_video() { console.log("%c xyApp page_video", "background:rgb(0,0,0);color:#fff"); // 关闭弹窗 xyApp.xyWaitOf(() => $(".iknow:visible").length > 0, 1000, 10).then(() => { let idx = 0; let timer = setInterval(() => { $(".iknow:visible").click(); idx++; if (idx >= 3) clearInterval(timer); }, 1000); }); xyApp.xyWaitOf(() => $(".SafetyIKonw:visible").length > 0, 1000, 10).then(() => { let idx = 0; let timer = setInterval(() => { $(".SafetyIKonw:visible").click(); idx++; if (idx >= 3) clearInterval(timer); }, 1000); }); // 启动视频监控定时器 if (xyApp.pageData.videoTimer != null) return; let timeout = 2; let lastTime = null; let checkTimesBak = 60; let checkTimes = checkTimesBak; xyApp.pageData.videoTimer = setInterval(async () => { try { if (xyApp.pageData.waitTime > 0) { xyApp.pageData.waitTime -= timeout; return; } let video = xyApp.xyGetVideo(); if (!video) return; // 视频已加载,显示播放状态 if (!xyApp.pageData.videoStarted) { xyApp.pageData.videoStarted = true; xyApp.xyUpdateVideoStatus(); } let title = "进度:" + curTime.toFixed(0) + "/" + xyApp.xyGetTotalTime().toFixed(0); $("title").text(title); // 更新悬浮面板进度 xyApp.xyUpdateVideoStatus(); } catch (e) { console.error("视频监控出错", e); } }, timeout * 1000); }, // 根据URL路由 async xyRunByUrl(url) { clearInterval(xyApp.pageData.videoTimer); xyApp.pageData.videoTimer = null; url = url.toLowerCase(); if (url.includes("/PersonalCenter/StudentIndex".toLowerCase())) { xyApp.page_video(); } }, // 初始化 async init() { console.log("%c xyApp init", "background:rgb(0,0,0);color:#fff"); xyApp.xyCreatePanel(); await xyApp.xyWaitMs(1000); try { await xyApp.xyWaitOf(() => $("body").length > 0, 1000, 30); await xyApp.xyWaitOf(() => { let found = false; $("a").each((i, el) => { if ($(el).text().trim() == "我的培训") { found = true; return false; } }); return found; }, 1000, 60); xyApp.xyRunByUrl(location.href); } catch (e) { console.error("xyApp init error", e); } }, }; // 3秒后检测,如果付费版本已运行则跳过免费版初始化 setTimeout(() => { if (typeof (zfk) == 'undefined') { xyApp.init(); } else { console.log('skip init'); } }, 3000); })();