// ==UserScript== // @name 🍀广西干部网络学院|脚本使用说明:https://doc.zhanyc.cn/pages/gxgbwlxy // @namespace free // @version 1.0 // @description 当前是免费版本,可免费使用视频自动播放、解除视频暂停限制、列表页面自动换课,学习视频数量受限。如需完整无人值守功能,含秒过、自动下一集、无限学习等高级功能需升级VIP版本解锁 // @include *://*.gxela.gov.cn/* // @include *://www.gxela.gov.cn/* // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @run-at document-end // @require https://scriptcat.org/lib/8488/jquery-2.2.4.min.js/jquery-2.2.4.min.js.js?sha384-rY/jv8mMhqDabXSo+UCggqKtdmBfd3qC2/KvyTDNQ6PcUJXaxK1tMepoQda4g5vB // @antifeature payment // @license Creative Commons // ==/UserScript== (function () { let gxFree = { docUrl: "https://doc.zhanyc.cn/pages/gxgbwlxy", pageData: { lastUrl: "", videoTimer: null, timerArr: [], lastVideoTime: 0, stuckCount: 0, menuRegistered: false }, _lic: { v: "20261202", k: 0x2E1B, p: [2, 3, 5, 7, 11, 13, 17] }, async init() { console.log("%c gxFree init", "background:rgb(0,0,0);color:#fff"); await gxFree.initPanel(); gxFree.registerMenu(); gxFree.pageData.lastUrl = location.href; setInterval(() => { if (gxFree.pageData.lastUrl !== location.href) { gxFree.pageData.lastUrl = location.href; gxFree.routeByUrl(location.href); } }, 500); gxFree.routeByUrl(location.href); }, registerMenu() { if (gxFree.pageData.menuRegistered) return; gxFree.pageData.menuRegistered = true; GM_registerMenuCommand("免费版使用说明", function () { window.open(gxFree.docUrl); }); }, async routeByUrl(url) { gxFree.stopVideoTimer(); url = (url + "").toLowerCase(); if (url.includes("study/index") && url.includes('type=lesson')) { gxFree.pageList(); } else if (url.includes("/lesson/detail?")) { gxFree.pageCourseDetail(); } else if (url.includes("/watch?")) { gxFree.pageVideo(); } else { gxFree.setPanelTip("等待进入学习页面"); } }, async pageList() { console.log("%c pageList", "background:rgb(0,0,0);color:#fff"); gxFree.clearAwaiting(); gxFree.setPanelTip("列表页面:查找未完成课程"); if (location.href.includes("type=class")) { gxFree.showTips("请手动进入班级页面后,脚本自动启动"); return; } await gxFree.awaitCondition(function () { return $(".lesson-list-item").length > 0; }); GM_setValue("gxFreeListUrl", location.href); await gxFree.sleepMs(1000); let $target = null; $(".lesson-list-item").each(function (i, el) { let jd = Number( $(el).find(".el-progress__text").text().trim().replace("%", "") ); if (jd < 100) { $target = $(el); return false; } }); if ($target == null) { gxFree.nextListPage(); return; } if (gxFree.showQuotaIfReached()) return; if (!(await gxFree.confirmNext("3秒后自动打开下一个未完成课程"))) return; let $btn = gxFree.findElByText($target.find("button"), "开始学习"); if ($btn) $btn.click(); }, async nextListPage() { let $next = $(".btn-next"); if ($next.length > 0 && !$next.is("[disabled]")) { let old = $(".class-card").text().trim(); $next.click(); await gxFree.awaitCondition(function () { return $(".class-card").text().trim() != old; }); await gxFree.sleepMs(500); gxFree.pageList(); } else { gxFree.showNotice("本页课程已全部学完,请手动查看其他课程"); } }, async pageCourseDetail() { console.log("%c pageCourseDetail", "background:rgb(0,0,0);color:#fff"); gxFree.setPanelTip("课程详情页面:等待开始学习按钮"); gxFree.awaitCondition(function () { return gxFree.findElByText($("button"), "已完成") != null; }).then(function (done) { if (!done) return; gxFree.confirmNext("本章节已完成,3秒后返回列表页面").then(function (ok) { if (ok) gxFree.backToList(); }); }); let found = await gxFree.awaitCondition(function () { return gxFree.findElByText($("button"), "开始学习") != null; }); if (!found) return; GM_setValue("gxFreeCourseUrl", location.href); if (gxFree.showQuotaIfReached()) return; if (!(await gxFree.confirmNext("3秒后自动开始学习本章节"))) return; let $btn = gxFree.findElByText($("button"), "开始学习"); if ($btn) $btn.click(); }, async pageVideo() { console.log("%c pageVideo", "background:rgb(0,0,0);color:#fff"); if (gxFree.pageData.videoTimer != null) return; if (gxFree.showQuotaIfReached()) return; gxFree.setPanelTip("视频页面:自动播放已启动"); gxFree.showTips("免费版已启动视频自动播放", 2000); gxFree.pageData.lastVideoTime = 0; gxFree.pageData.stuckCount = 0; let step = 2; gxFree.pageData.videoTimer = setInterval(async function () { try { if ($("xg-start.xgplayer-start:visible").length > 0) { $("xg-start.xgplayer-start").click(); } let video = $("video")[0]; if (!video) return; video.volume = 0; let cur = Number(video.currentTime) || 0; let total = Number(video.duration) || 0; gxFree.setVideoProgress(cur, total); if (total > 0 && cur == gxFree.pageData.lastVideoTime) { gxFree.pageData.stuckCount += step; if (gxFree.pageData.stuckCount >= 60) { gxFree.pageData.stuckCount = 0; gxFree.stopVideoTimer(); if (await gxFree.confirmNext("检测到视频长时间未播放,3秒后返回列表页面")) { gxFree.backToList(); } return; } } else { gxFree.pageData.stuckCount = 0; } gxFree.pageData.lastVideoTime = cur; if (total > 0 && cur + 5 >= total) { gxFree.stopVideoTimer(); gxFree.handleVideoFinish(); return; } if (video.paused) { video.play(); } } catch (e) { console.error("视频页面定时器出错", e); } }, step * 1000); }, stopVideoTimer() { if (gxFree.pageData.videoTimer != null) { clearInterval(gxFree.pageData.videoTimer); gxFree.pageData.videoTimer = null; } }, async handleVideoFinish() { console.log("%c handleVideoFinish", "background:rgb(0,0,0);color:#fff"); let total = gxFree.getVideoQuota(); let count = gxFree.readLearnedCount() + 1; gxFree.writeLearnedCount(count); gxFree.refreshPanel(); gxFree.setPanelTip("已完成 " + count + "/" + total + " 个视频"); if (count >= total) { gxFree.warnQuota(gxFree.calcQuotaStatus(count, total)); return; } gxFree.showToast( "当前已学习 " + count + "/" + total + " 个视频,准备自动换课", 3000 ); await gxFree.sleepMs(3000); if (await gxFree.confirmNext("视频已学完,3秒后返回列表页面自动切换下一课")) { gxFree.backToList(); } }, backToList() { let url = GM_getValue("gxFreeListUrl", ""); if (!url) { gxFree.showNotice( "未记录到列表页面地址,请手动前往列表页面,脚本会自动打开未完成课程" ); return; } try { top.location.href = url; } catch (e) { location.href = url; } }, getVideoQuota() { let lic = gxFree._lic; let raw = lic.v + "|" + lic.k.toString(16); let hash = 0; for (let i = 0; i < raw.length; i++) { hash = ((hash * 31) + raw.charCodeAt(i)) | 0; } let abs = Math.abs(hash); let seed1 = abs % 16; let seed2 = lic.p.reduce(function (a, b) { return a + b; }, 0) % 7; let seed3 = (lic.k >> 3) & 0x7; let table = [10, 9, 11, 12, 10, 8, 9, 11, 10, 12, 10, 10, 8, 11, 10, 9]; let idx = (seed1 + seed2 + seed3) % 16; let base = table[idx]; let check = lic.p.reduce(function (a, b) { return a + b; }, 0) % 2 === 0 ? 0 : 1; return base - check; }, readLearnedCount() { let n = Number(GM_getValue("gxFreeLearnedCount", 0)); if (isNaN(n) || n < 0) n = 0; return n; }, writeLearnedCount(n) { GM_setValue("gxFreeLearnedCount", n); }, showQuotaIfReached() { let status = gxFree.calcQuotaStatus( gxFree.readLearnedCount(), gxFree.getVideoQuota() ); if (status.allowed) return false; gxFree.warnQuota(status); return true; }, calcQuotaStatus(current, limit) { let diff = limit - current; return { allowed: diff > 0, remain: Math.max(0, diff), current: current, total: limit }; }, warnQuota(status) { gxFree.showVipUpgradeBox( gxFree.buildQuotaTitle(status), gxFree.buildQuotaText(status) ); }, buildQuotaTitle(status) { let titles = ["免费额度已用完", "试用次数已耗尽", "体验次数已达上限"]; return titles[status.total % titles.length]; }, buildQuotaText(status) { let templates = [ "免费脚本可自动学习前{total}个视频,目前免费额度已经用完,请升级VIP版本后继续使用。", "当前免费版本支持{total}个视频自动学习,您的额度已用完,升级VIP可解锁无限学习。", "体验次数{total}次已用完,如需继续自动学习请升级VIP版本。" ]; let text = templates[(status.total + status.current) % templates.length]; return text.replace(/\{total\}/g, status.total); }, async initPanel() { await gxFree.awaitCondition(function () { return $("body").length > 0; }); if ($("#gxFreePanel").length > 0) return; let html = `