// ==UserScript== // @name 新国开AI云端自动刷课 // @namespace https://github.com/barryallennnnn // @version 2.1.1 // @description 新国开AI自动刷课 // @author 王杰 // @match *://lms.ouchn.cn/course/* // @match *://lms.ouchn.cn/mod/* // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @grant unsafeWindow // @run-at document-end // ==/UserScript== (function () { 'use strict'; const BACKEND_URL = "https://www.jirowang.eu.org/api/get-core-code"; /* ================= 样式 ================= */ const panelCSS = ` #gk-panel, #gk-auth-panel {position:fixed;inset:12px auto auto 12px;width:360px;background:#fff;border:1px solid #ddd;border-radius:8px;font-family:system-ui;box-shadow:0 4px 20px rgba(0,0,0,.15);z-index:99999;display:flex;flex-direction:column;max-height:90vh} #gk-head, #gk-auth-head {padding:10px 12px;background:#673ab7;color:#fff;font-size:15px;display:flex;justify-content:space-between;align-items:center} #gk-close, #gk-auth-close {background:none;border:none;color:#fff;font-size:18px;cursor:pointer} #gk-body, #gk-auth-body {padding:12px;display:flex;flex-direction:column;gap:10px;overflow:auto} #gk-bar{height:10px;background:#eee;border-radius:5px;overflow:hidden} #gk-fill{height:100%;background:#673ab7;width:0%;transition:width .3s} #gk-log{min-height:160px;max-height:300px;font-size:12px;border:1px solid #eee;border-radius:4px;padding:6px;overflow-y:auto;background:#fafafa;line-height:1.4; word-break: break-all;} #gk-stats{font-size:12px;color:#666} .gk-btn{padding:8px 14px;border:none;border-radius:4px;background:#673ab7;color:#fff;font-size:14px;cursor:pointer; text-align:center;} .gk-btn:disabled{background:#bbb;cursor:not-allowed} .gk-succ{color:#2e7d32} .gk-err{color:#c62828} .gk-info{color:#1565c0} .gk-input{padding:8px;border:1px solid #ddd;border-radius:4px;font-size:14px;width:100%;box-sizing:border-box;} .gk-auth-row{display:flex;flex-direction:column;gap:5px;} `; const getGlobalData = () => { return typeof unsafeWindow !== 'undefined' ? unsafeWindow.globalData : window.globalData; }; const getMachineCode = () => { const gd = getGlobalData(); if (!gd || !gd.user || !gd.user.id) { return "ERROR_NO_USER"; } const uid = String(gd.user.userNo || gd.user.id); let hash = 0; for (let i = 0; i < uid.length; i++) { hash = ((hash << 5) - hash) + uid.charCodeAt(i); hash |= 0; } return Math.abs(hash).toString(16).toUpperCase() + "GK"; }; const currentMac = getMachineCode(); const storageKey = 'gk_act_' + currentMac; GM_registerMenuCommand("🔄 清除当前账号授权", () => { if (confirm("确定要清除【当前登录账号】的激活状态吗?\n不影响其他已激活的账号。")) { GM_deleteValue(storageKey); alert("当前账号授权已清除!网页即将刷新。"); location.reload(); } }); function initAuthPanel() { if (document.querySelector('#gk-auth-panel')) return; if (currentMac === "ERROR_NO_USER") { console.error("未能读取到账号信息,请确认在正确的学习页面!"); return; } const style = document.createElement('style'); style.textContent = panelCSS; document.head.appendChild(style); const panel = document.createElement('div'); panel.id = 'gk-auth-panel'; const gd = getGlobalData(); const userName = gd.user.name || "未知用户"; panel.innerHTML = `
脚本授权验证
请将此码发送给作者QQ:1013079885获取当前账号的激活码
`; document.body.appendChild(panel); document.querySelector('#gk-auth-close').onclick = () => panel.remove(); document.querySelector('#gk-copy').onclick = () => { GM_setClipboard(currentMac); alert('账号授权码已复制!'); }; document.querySelector('#gk-verify').onclick = () => { const inputCode = document.querySelector('#gk-activation').value.trim(); if (!inputCode) return alert('请输入激活码!'); GM_setValue(storageKey, inputCode); alert('激活码已保存!请在学习面板点击开始学习进行验证。'); panel.remove(); initPanel(); }; } let isRunning = false; function initPanel() { if (document.querySelector('#gk-panel')) return; const style = document.createElement('style'); style.textContent = panelCSS; document.head.appendChild(style); const panel = document.createElement('div'); panel.id = 'gk-panel'; panel.innerHTML = `
新国开云端刷课 By:王杰
准备就绪
`; document.body.appendChild(panel); document.querySelector('#gk-run').onclick = () => requestCloudCore(); document.querySelector('#gk-close').onclick = () => panel.remove(); } function requestCloudCore() { if (isRunning) { alert('已在运行中'); return; } isRunning = true; const logEl = document.querySelector('#gk-log'); const appendLog = (msg, color='black') => { logEl.innerHTML += `
[${new Date().toLocaleTimeString()}] ${msg}
`; logEl.scrollTop = logEl.scrollHeight; }; const code = GM_getValue(storageKey, ''); if (!code) { alert('未能获取到该账号的激活码,请重新激活!'); GM_deleteValue(storageKey); location.reload(); return; } appendLog("正在连接云端大脑验证账号授权...", "#1565c0"); GM_xmlhttpRequest({ method: 'POST', url: BACKEND_URL, data: JSON.stringify({ mac: currentMac, code: code }), headers: { 'Content-Type': 'application/json' }, onload: function(response) { try { const res = JSON.parse(response.responseText); if (res.success) { appendLog("授权验证通过!获取核心算法中...", "#2e7d32"); const loadCore = new Function(res.script); loadCore(); const realWindow = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window; const gd = realWindow.globalData; const coreFn = realWindow.cloud_learnTech; if (typeof coreFn === 'function') { coreFn(gd); } else { appendLog("云端方法装载异常,请联系作者修补。", "red"); console.log("排错信息:未能找到 cloud_learnTech 函数"); isRunning = false; } } else { appendLog(`拦截:${res.msg}`, "red"); alert(`云端验证失败:${res.msg}\n可能由于激活码输入错误或被封禁,需重新输入!`); GM_deleteValue(storageKey); isRunning = false; location.reload(); } } catch (e) { appendLog(`解析云端数据失败:${e.message}`, "red"); isRunning = false; } }, onerror: function() { appendLog("无法连接服务器!可能原因:1.无网络 2.防火墙未放行", "red"); isRunning = false; } }); } // 入口路由 if (currentMac !== "ERROR_NO_USER") { // 检查当前账号是否有保存过激活码 if (GM_getValue(storageKey, '')) { initPanel(); } else { initAuthPanel(); } } })();