// ==UserScript== // @name 广财慕课|使用说明:http://doc.zhanyc.cn/pages/gcmk/ - 免费版(视频自动播放、解除暂停限制) // @namespace free // @version 1.0 // @description 当前是免费版本,只包含了视频页面自动播放、解除播放暂停限制、2倍速功能。如需自动下一集、自动换课程、秒过、考试答题、全自动无人值守高级功能可升级付费版本|接各类脚本开发、代挂工作,微信:zhanyc_cn 个人网站:http://doc.zhanyc.cn // @include *://*.gdufemooc.cn/* // @include *://*.yuketang.cn/* // @grant GM_addStyle // @run-at document-end // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // @license Creative Commons // ==/UserScript== (function () { let $jq = $; unsafeWindow.$jq = $; let docUrl = "http://doc.zhanyc.cn/pages/gcmk/"; let FREEJS = { pageData: { video: { index: null, }, }, init() { console.log( "%c [免费版] 广财慕课 init", "background:rgb(0,0,0);color:#fff" ); FREEJS.addFloatingPanel(); FREEJS.runByUrl(location.href); }, runByUrl(url) { if (url.includes("/video/")) { FREEJS.page_video(); } else if (url.includes("/studycontent")) { FREEJS.page_paidTip(); } else if (url.includes("/mytraining/detail/")) { FREEJS.page_paidTip(); } }, // 其他页面提示付费版功能 page_paidTip() { console.log( "%c [免费版] 当前页面需要付费版支持", "background:rgb(255,0,0);color:#fff" ); FREEJS.updatePanelContent(`

当前功能需要付费版本支持

付费版可解锁:

✅ 自动化看课换课

✅ 自动换课程

✅ 全自动无人值守

查看付费版本详情

`); }, // 添加悬浮引流面板 addFloatingPanel() { if (document.getElementById("freeGCMKPanel")) return; GM_addStyle(` #freeGCMKPanel { position: fixed; left: 0; top: 0; z-index: 99999; background: rgba(0, 0, 0, 0.85); color: #fff; font-size: 13px; border-radius: 0 0 8px 0; padding: 10px 12px; max-width: 280px; box-shadow: 0 2px 10px rgba(0,0,0,0.3); font-family: "Microsoft YaHei", sans-serif; } #freeGCMKPanel .panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 6px; } #freeGCMKPanel .panel-title { font-weight: bold; font-size: 14px; color: #ffcc00; } #freeGCMKPanel .panel-close { cursor: pointer; color: #999; font-size: 18px; line-height: 1; padding: 0 4px; } #freeGCMKPanel .panel-close:hover { color: #fff; } #freeGCMKPanel .panel-body { line-height: 1.6; } #freeGCMKPanel .panel-body a { color: #ffcc00; text-decoration: underline; } #freeGCMKPanel .video-status { margin-top: 8px; padding: 8px; background: rgba(46, 204, 113, 0.2); border: 1px solid rgba(46, 204, 113, 0.4); border-radius: 4px; text-align: center; font-weight: bold; font-size: 14px; } #freeGCMKPanel .video-status.running { color: #2ecc71; } #freeGCMKPanel .video-status .progress-text { color: #fff; font-size: 13px; margin-top: 4px; } #freeGCMKPanel .contact-info { margin-top: 8px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.15); font-size: 12px; color: #aaa; } `); let panelHtml = `
广财慕课脚本 - 免费版 ×

如需使用全功能版本,请通过下方地址安装付费版本购买授权后可使用

${docUrl}

接各类脚本开发、代挂、网站小程序开发工作,微信:zhanyc_cn
`; let panel = document.createElement("div"); panel.id = "freeGCMKPanel"; panel.innerHTML = panelHtml; document.body.appendChild(panel); document.getElementById("freePanelClose").onclick = function () { document.getElementById("freeGCMKPanel").style.display = "none"; }; }, updatePanelContent(html) { let body = document.getElementById("freeGCMKPanelBody"); if (body) body.innerHTML = html; }, // 视频页面核心功能 async page_video() { console.log( "%c [免费版] page_video", "background:rgb(0,0,0);color:#fff" ); if (FREEJS.pageData.video.index != null) return; // 显示视频状态面板 let statusEl = document.getElementById("freeGCMKVideoStatus"); if (statusEl) statusEl.style.display = "block"; // 解除暂停限制(document.hasFocus劫持) await FREEJS.waitForElement(function () { return unsafeWindow.document.hasFocus; }); unsafeWindow.document.hasFocus = function () { return true; }; var timeout = 2; FREEJS.pageData.video.index = setInterval(async function () { try { var video = FREEJS.getVideo(); if (!video) { console.log( "%c [免费版] no video", "background:rgb(0,0,0);color:#fff" ); return; } // 处理"继续学习"弹窗及类似确认弹窗 var continueBtn = FREEJS.getElByText("button", "继续学习"); if (continueBtn) continueBtn.click(); // 更新进度显示 var curTime = FREEJS.getCurTime(); var totalTime = FREEJS.getTotalTime(); var progressText = "进度:" + curTime.toFixed(0) + "/" + totalTime.toFixed(0); var progEl = document.getElementById("freeGCMKProgress"); if (progEl) progEl.textContent = progressText; document.title = "[免费版] " + progressText; // 检查是否播放完成 var isFinish = FREEJS.isPlayFinish(); if (isFinish) { var statusSpan = document.querySelector( "#freeGCMKVideoStatus span" ); if (statusSpan) statusSpan.textContent = "⏹ 视频播放完成"; clearInterval(FREEJS.pageData.video.index); FREEJS.pageData.video.index = null; return; } // 检查是否在播放,不在则播放 var isPlay = await FREEJS.videoIsPlay(); if (!isPlay) { FREEJS.play(); } // 设置2倍速 if (video.playbackRate != 2) { video.playbackRate = 2; } // 静音 if (video.volume != 0) { video.volume = 0; } } catch (e) { console.error("[免费版] 视频页面定时器出错", e); } }, timeout * 1000); }, getVideo() { return document.querySelector("video"); }, play() { var video = FREEJS.getVideo(); if (video) { video.volume = 0; setTimeout(function () { video.play(); }, 200); } }, videoIsPlay() { return new Promise(function (resolve) { try { var curTime = FREEJS.getCurTime(); setTimeout(function () { var time1 = FREEJS.getCurTime(); var res = time1 > curTime; if (res) { setTimeout(function () { var time2 = FREEJS.getCurTime(); resolve(time2 > time1); }, 100); } else { resolve(false); } }, 100); } catch (e) { resolve(false); } }); }, isPlayFinish() { try { return ( FREEJS.getTotalTime() > 0 && FREEJS.getCurTime() + 5 >= FREEJS.getTotalTime() ); } catch (e) { return false; } }, getCurTime() { try { return FREEJS.getVideo() ? FREEJS.getVideo().currentTime : 0; } catch (e) { return 0; } }, getTotalTime() { try { return FREEJS.getVideo() ? FREEJS.getVideo().duration : 0; } catch (e) { return 0; } }, getElByText(query, text) { var els = document.querySelectorAll(query); for (var i = 0; i < els.length; i++) { if ( els[i].textContent.trim() === text && els[i].offsetParent !== null ) { return els[i]; } } return null; }, waitForElement(fun, interval, timeout) { if (!interval) interval = 1000; if (!timeout) timeout = 30; return new Promise(function (resolve, reject) { if (fun()) return resolve(); var maxTime = timeout * 1000; var timer = setInterval(function () { maxTime -= interval; if (maxTime < 0) { clearInterval(timer); return reject(); } if (fun()) { clearInterval(timer); resolve(); } }, interval); }); }, waitTimeout(ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }, }; // 3秒后检查是否有付费版本,无则初始化免费版 setTimeout(function () { if (typeof unsafeWindow.zfk === "undefined") { FREEJS.init(); } else { console.log("[免费版] 检测到付费版本,跳过初始化"); } }, 3000); if (!unsafeWindow.FREEJS) unsafeWindow.FREEJS = FREEJS; })();