// ==UserScript== // @name 中小学智慧教育平台每周任务积分助手-免费版 // @namespace https://basic.smartedu.cn/ // @version 1.1.9 // @description UI操作版:在当前标签页逐个打开真实课时页面,自动化点击页面上的真实按钮(播放/点赞/收藏/评分/存库/育小苗AI对话)完成每周积分任务,全程可见,约26.9分/周。支持脚本猫(ScriptCat)与油猴(Tampermonkey)。 // @author weekly-points // @match https://basic.smartedu.cn/* // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_xmlhttpRequest // @grant GM_addStyle // @connect ykt.eduyun.cn // @connect *.ykt.eduyun.cn // @connect x-incentive-service.ykt.eduyun.cn // @connect e-favorite-api.ykt.eduyun.cn // @connect ykt.cbern.com.cn // @connect *.ykt.cbern.com.cn // @connect s-file-1.ykt.cbern.com.cn // @connect s-file-2.ykt.cbern.com.cn // @connect api.ykt.cbern.com.cn // @run-at document-idle // @noframes // ==/UserScript== (function() { "use strict"; const CFG = { APP_ID: "e5649925-441d-4a53-b525-51a2f1c4e0a8", TOKEN_LS_KEY: "ND_UC_AUTH-e5649925-441d-4a53-b525-51a2f1c4e0a8&ncet-xedu&token", TARGETS: { browse: 5, play: 5, save: 5, like: 1, fav: 2, rate: 1, ai: 5 }, TEXTBOOKS: [ "fa60dc59-2eea-444d-80fb-f008d6b8d572" ], AI_PROMPTS: [ "你好,请简单介绍一下你自己", "请推荐一节适合预习的数学课程", "教师如何保存资源到我的资源库?", "我想找语文三年级下册的教材,怎么找?", "平台里怎么提交资源评价?", "请介绍一下平台的人工智能教育栏目", "如何查看我的积分明细?", "帮我找一节初中物理实验课" ], READY_TIMEOUT: 25e3, PLAY_MAX: 18e4, BROWSE_WAIT: 5e3, DELAY: [ 1500, 4e3 ] }; const API = { balance: "https://x-incentive-service.ykt.eduyun.cn/v1/incentives/my_package", history: "https://x-incentive-service.ykt.eduyun.cn/v1/incentives/actions/search", favors: "https://e-favorite-api.ykt.eduyun.cn/v1/user_favors", docList: "https://doc-center.ykt.eduyun.cn/v1.0/c/search/action/query_lately?$limit=({O},50)&$orderby=last_open+desc&scope=file", docDelete: "https://doc-center.ykt.eduyun.cn/v1.0/c/document/batch_delete?clear=true" }; const TASK_NAMES = { browse: "浏览资源", play: "播放视频", save: "存我的资源库", like: "点赞", fav: "收藏", rate: "提交评价", ai: "育小苗AI对话" }; const _SA = "swp#2026^fr"; const _SB = "ee!notice@x7Qz"; const _NB = [ "levcy4y117z3g9/DgZjOifv7h972narWnsvNlaa/2IaPsdr+gd2sitPuj//spMOMtcfmkeSV2oSL3//flf7L", "l8rPxKaY26Hwj9D9gK7Biv7JQzQRWNDv3pfN1MWHsde504/U7Yqd9FdMW1pVeUEBYA==" ]; const _HE1 = "efccbd5de25c4c0b4e025f32b1a633cc"; const _HE2 = "523c59bafb6477de8341bef4cebb01a8"; let _OK = null; function _dec(b64) { const tb = Uint8Array.from(atob(b64), c => c.charCodeAt(0)); const sb = (new TextEncoder).encode(_SA + _SB); const out = new Uint8Array(tb.length); for (let i = 0; i < tb.length; i++) out[i] = tb[i] ^ sb[i % sb.length]; return (new TextDecoder).decode(out); } async function _boot() { if (_OK !== null) return _OK; try { const n0 = _dec(_NB[0]); const n1 = _dec(_NB[1]); const data = (new TextEncoder).encode(n0 + "" + n1 + "" + _SA + _SB); const digest = await crypto.subtle.digest("SHA-256", data); const hex = [ ...new Uint8Array(digest) ].map(b => b.toString(16).padStart(2, "0")).join(""); const rhex = hex.split("").reverse().join(""); _OK = rhex === _HE2 + _HE1; if (!_OK) console.error("[积分助手] 完整性校验失败:插件信息被修改,已停止运行。请恢复原始脚本。"); } catch (e) { _OK = false; console.error("[积分助手] 完整性校验异常,已停止运行。"); } return _OK; } function _noticeHTML() { const n0 = _dec(_NB[0]); const n1 = _dec(_NB[1]); const i = n1.lastIndexOf(":"); const head = i >= 0 ? n1.slice(0, i + 1) : n1; const num = i >= 0 ? n1.slice(i + 1) : ""; const esc = s => s.replace(/&/g, "&").replace(//g, ">"); return `
" + text.replace(/[<>]/g, "") + "
"); } else { document.execCommand("selectAll", false, null); document.execCommand("insertText", false, text); ed.dispatchEvent(new InputEvent("input", { bubbles: true, data: text, inputType: "insertText" })); } } catch (e) { return false; } await sleep(600); const counter = (document.querySelector(".ai-assistant2-inputbox-editStatus-limit") || {}).innerText || ""; return (ed.textContent || "").trim().length > 0 && !counter.startsWith("0/"); } function aiSendBtn() { const icon = document.querySelector(".ai-assistant2-inputbox-editIcon"); if (icon) return icon; const root = aiRoot(); const byCls = root.querySelectorAll('[class*="send"], [class*="Send"]'); if (byCls.length) return byCls[byCls.length - 1]; const ed = aiEditor(); if (!ed) return null; const box = ed.closest('[class*="inputbox"], [class*="input-box"]') || ed.parentElement.parentElement; if (!box) return null; const icons = box.querySelectorAll('img,svg,i,button,[class*="icon"],[class*="Icon"]'); return icons.length ? icons[icons.length - 1] : null; } async function aiNewChat() { const btn = document.querySelector(".ai-assistant2-operator-newtalk-icon"); if (!btn) return false; if (!document.querySelector(".ai-assistant2-message-list")) return true; btn.click(); const t0 = Date.now(); while (Date.now() - t0 < 8e3) { await sleep(600); const home = !!document.querySelector(".ai-assistant2-homebox"); const gone = !document.querySelector(".ai-assistant2-message-list"); const counter = (document.querySelector(".ai-assistant2-inputbox-editStatus-limit") || {}).innerText || ""; if ((home || gone) && counter.indexOf("0/") === 0) return true; } return false; } async function runAiRoundsOnPage(state) { if (!await aiPanelOpen()) { log(" ✘ 未找到育小苗入口或面板未打开(请确认已登录)"); return; } while (state.ai < CFG.TARGETS.ai) { const q = CFG.AI_PROMPTS[state.ai % CFG.AI_PROMPTS.length]; const fresh = await aiNewChat(); if (!fresh) log(" ⚠ 未能新建对话,将继续当前对话"); if (!await aiType(q)) { log(` ✘ 第 ${state.ai + 1} 轮输入框写入失败,停止AI任务`); return; } const btn = aiSendBtn(); if (!btn) { log(" ✘ 未找到发送按钮,停止AI任务"); return; } btn.click(); pushOnce(state, "ai"); saveState(state); log(` 对话 ${state.ai}/${CFG.TARGETS.ai} ✓${fresh ? "(新对话)" : ""}:${q}`); if (state.ai < CFG.TARGETS.ai) await sleep(9e3 + Math.random() * 4e3); } log(" AI对话完成"); } function badge(text, stopBtn = true) { let b = document.getElementById("swp-ui-badge"); if (!b) { b = document.createElement("div"); b.id = "swp-ui-badge"; b.style.cssText = "position:fixed;left:16px;bottom:16px;z-index:999999;display:flex;align-items:center;gap:8px;" + "background:rgba(30,41,59,.92);color:#fff;padding:8px 12px;border-radius:8px;font-size:12px;box-shadow:0 4px 14px rgba(0,0,0,.3)"; document.body.appendChild(b); } b.innerHTML = `${text}` + (stopBtn ? `停止` : ""); const stop = b.querySelector("#swp-ui-stop"); if (stop) stop.addEventListener("click", () => { GM_deleteValue("swp_ui_job"); log("⏹ 已手动停止任务"); b.remove(); }); } function badgeRemove() { const b = document.getElementById("swp-ui-badge"); if (b) b.remove(); } const getJob = () => GM_getValue("swp_ui_job", null); const setJob = j => { j ? GM_setValue("swp_ui_job", j) : GM_deleteValue("swp_ui_job"); }; async function startJob(tasks) { if (!await _boot()) return; if (getJob()) { log("已有进行中的任务,请先「继续」或「停止」"); updateUI(); return; } const state = loadState(); const resTasks = tasks.filter(t => t !== "ai"); const aiNeeded = tasks.includes("ai") && state.ai < CFG.TARGETS.ai; const resNeed = Math.max(0, ...resTasks.map(t => Math.max(0, CFG.TARGETS[t] - doneCount(state, t)))); const need = Math.max(resNeed, aiNeeded ? 1 : 0); if (need <= 0) { log("本周所选任务均已完成,无需执行"); updateUI(); return; } const lessons = await pickLessons(state, resTasks.length ? resTasks : [ "ai" ], need); GM_setValue("swp_hb_cnt", 0); if (resTasks.includes("save")) { log("▶ 检查个人资源库容量…"); await libCleanupLegacy(); } let b0 = null; try { b0 = (await queryBalance()).balance; } catch (e) {} setJob({ tasks: resTasks, ai: aiNeeded, queue: lessons, idx: 0, origin: location.href, startedAt: Date.now(), b0: b0 }); log(`🚀 启动UI任务:共 ${lessons.length} 个课时页面${aiNeeded ? "(含育小苗AI对话)" : ""},将在本标签页依次打开真实页面操作`); const first = await getLesson(lessons[0]); location.href = lessonUrl(first); } async function runLessonWork(job) { if (!await _boot()) return; const lessonId = new URLSearchParams(location.search).get("activityId"); const state = loadState(); const remaining = {}; job.tasks.forEach(t => { remaining[t] = Math.max(0, CFG.TARGETS[t] - doneCount(state, t)); }); const tasksHere = job.tasks.filter(t => remaining[t] > 0); const aiHere = !!job.ai && job.idx === 0 && state.ai < CFG.TARGETS.ai; badge(`积分助手:正在处理课时 ${job.idx + 1}/${job.queue.length}`, true); log(`▶ 课时 ${job.idx + 1}/${job.queue.length}`); if (!tasksHere.length && !aiHere) { log(" 本课时无待办任务"); return advance(job); } if (!await waitReady()) { log(" ✘ 页面加载超时"); return advance(job); } if (aiHere) { badge(`积分助手:育小苗AI对话中 ${job.idx + 1}/${job.queue.length}`, true); log("▶ 育小苗AI对话(真实面板操作)"); await runAiRoundsOnPage(state); if (!getJob()) { badgeRemove(); log("⏹ 任务已停止,流程终止"); return; } } if (remaining.browse > 0) { badge(`积分助手:浏览页面中 ${job.idx + 1}/${job.queue.length}`, true); await sleep(CFG.BROWSE_WAIT); pushOnce(state, "browse", lessonId); saveState(state); log(" 浏览 ✓"); remaining.browse--; } let playStarted = false; if (remaining.play > 0) { if (await uiPlay()) { playStarted = true; pushOnce(state, "play", lessonId); saveState(state); log(" 播放 ✓(已静音,真实观看中)"); remaining.play--; const startHb = hbCount(); const targetHb = startHb + Math.max(1, remaining.play + 1); const t0 = Date.now(); while (Date.now() - t0 < CFG.PLAY_MAX) { if (!getJob()) { badgeRemove(); log("⏹ 任务已停止,流程终止"); return; } const hb = hbCount(); const left = Math.round((CFG.PLAY_MAX - (Date.now() - t0)) / 1e3); badge(`积分助手:观看中 ${job.idx + 1}/${job.queue.length} · 心跳 ${hb - startHb}/${targetHb - startHb} · 最长剩 ${left}s`, true); if (hb >= targetHb) { log(` 观看完成:新增心跳 ${hb - startHb} 次`); break; } await sleep(5e3); } } else log(" ✘ 未找到播放按钮或视频未播放"); } if (remaining.like > 0) { const r = uiLike(); if (r === "already") log(" 点赞:本课时已赞过,跳过"); else if (r) { pushOnce(state, "like", lessonId); saveState(state); log(" 点赞 ✓"); remaining.like--; } else log(" ✘ 未找到点赞按钮"); await randDelay(); } if (remaining.fav > 0) { const r = await uiFav(); if (r === "already") log(" 收藏:本课时已收藏过,跳过"); else if (r) { pushOnce(state, "fav", lessonId); saveState(state); log(" 收藏 ✓"); remaining.fav--; if (GM_getValue("swp_unfav", false)) { try { await xFetch(`${API.favors}?content_id=${lessonId}&content_type=national_lesson`, { method: "DELETE" }); log(" 已自动取消收藏"); } catch (e) { log(" 自动取消收藏失败(不影响积分)"); } } } else log(" ✘ 未找到收藏按钮"); await randDelay(); } if (remaining.rate > 0) { if (await uiRate()) { pushOnce(state, "rate", lessonId); saveState(state); log(" 评价 ✓(五星)"); remaining.rate--; } else log(" ✘ 评分流程未完成"); await randDelay(); } if (remaining.save > 0) { let before = []; try { before = (await libList()).map(i => i.id); } catch (e) {} if (uiSave()) { pushOnce(state, "save", lessonId); saveState(state); log(" 存库 ✓"); remaining.save--; await sleep(3e3); await libDeleteNewlyAdded(before); } else log(" ✘ 未找到存库按钮"); await sleep(2e3); } advance(job); } async function advance(job) { if (!getJob()) { badgeRemove(); log("⏹ 任务已停止,流程终止"); return; } job.idx += 1; if (job.idx < job.queue.length) { setJob(job); const next = await getLesson(job.queue[job.idx]); log(`↪ 跳转下一个课时:${next.title}`); location.href = lessonUrl(next); } else { const origin = job.origin; setJob(null); log("🎉 全部队列完成"); let summary = "积分助手:全部完成,正在返回…"; try { await sleep(4e3); const b1 = (await queryBalance()).balance; if (job.b0 != null && typeof b1 === "number") { const diff = b1 - job.b0; log(`💰 本次任务:积分 ${job.b0} → ${b1},本次共得 +${diff.toFixed(1)} 分`); summary = `积分助手:全部完成 · 本次共得 +${diff.toFixed(1)} 分`; } else { log(`💰 当前总积分:${b1}`); summary = `积分助手:全部完成 · 当前 ${b1} 分`; } const s = loadState(); s._balance = b1; saveState(s); if (balEl) balEl.textContent = `当前总积分:${b1}`; } catch (e) {} badge(summary, false); setTimeout(() => { location.href = origin; }, 3e3); } } async function queryBalance() { return await xFetch(API.balance); } async function queryHistory(n = 10) { const j = await xFetch(`${API.history}?page_size=${n}&page_no=0`); return (j.items || []).map(i => ({ t: (i.biz_date || "").slice(5, 16).replace("T", " "), amt: i.amount, rule: i.rule_id, remark: i.remark })); } GM_addStyle(`\n #swp-fab{position:fixed;right:16px;bottom:88px;z-index:999999;width:44px;height:44px;border-radius:50%;\n background:linear-gradient(135deg,#3b82f6,#6366f1);color:#fff;font-size:12px;line-height:44px;text-align:center;\n cursor:pointer;box-shadow:0 2px 10px rgba(0,0,0,.25);user-select:none;font-weight:600}\n #swp-panel{position:fixed;right:16px;bottom:140px;z-index:999999;width:320px;max-height:70vh;display:none;flex-direction:column;\n background:#fff;border-radius:10px;box-shadow:0 6px 24px rgba(0,0,0,.22);overflow:hidden;font-size:12px;color:#333}\n #swp-panel.open{display:flex}\n .swp-head{padding:8px 12px;background:#f0f5ff;font-weight:600;display:flex;justify-content:space-between;align-items:center}\n .swp-head span:last-child{cursor:pointer;color:#999;font-weight:400}\n .swp-notice{margin:6px 12px 0;padding:6px 8px;background:#fffbeb;border:1px solid #fde68a;border-radius:6px;color:#92400e;line-height:1.7;font-size:11px}\n .swp-balance{padding:6px 12px;color:#1d4ed8;font-weight:600}\n .swp-progress{padding:0 12px 4px;color:#666;line-height:1.7}\n .swp-progress b{color:#16a34a;font-weight:600}\n .swp-btns{display:grid;grid-template-columns:1fr 1fr;gap:6px;padding:8px 12px}\n .swp-btns button{border:1px solid #d1d5db;background:#f9fafb;border-radius:6px;padding:4px 2px;cursor:pointer;font-size:12px}\n .swp-btns button:hover{background:#eef2ff;border-color:#6366f1}\n .swp-btns button:disabled{opacity:.5;cursor:not-allowed}\n .swp-btn-all{grid-column:1/3;background:#4f46e5!important;color:#fff!important;border-color:#4f46e5!important;font-weight:600;padding:6px!important}\n .swp-btn-resume{grid-column:1/3;background:#f59e0b!important;color:#fff!important;border-color:#f59e0b!important;font-weight:600}\n .swp-opts{padding:0 12px 6px;color:#666;display:flex;justify-content:space-between;align-items:center}\n .swp-log{flex:1;overflow:auto;margin:0 12px 10px;border-top:1px solid #eee;padding-top:6px;white-space:pre-wrap;word-break:break-all;line-height:1.6;min-height:80px}\n `); let logEl, progEl, balEl, panel; function progressText(state) { const T = CFG.TARGETS; const n = k => doneCount(state, k); return `浏览 ${n("browse")}/${T.browse} | 播放 ${n("play")}/${T.play} | 存库 ${n("save")}/${T.save} | ` + `点赞 ${n("like")}/${T.like} | 收藏 ${n("fav")}/${T.fav} | 评价 ${n("rate")}/${T.rate} | AI ${n("ai")}/${T.ai}`; } function updateUI() { const state = loadState(); const job = getJob(); if (progEl) progEl.innerHTML = progressText(state); const resumeBtn = panel.querySelector('[data-act="resume"]'); if (resumeBtn) resumeBtn.remove(); if (job) { const btn = document.createElement("button"); btn.className = "swp-btn-resume"; btn.setAttribute("data-act", "resume"); btn.textContent = `任务进行中(${Math.min(job.idx + 1, job.queue.length)}/${job.queue.length})· 点击继续`; panel.querySelector(".swp-btns").appendChild(btn); } [ ...panel.querySelectorAll(".swp-btns button") ].forEach(b => { const act = b.getAttribute("data-act"); if (act !== "resume" && act !== "stop" && act !== "balance" && act !== "clearlog" && act !== "reset") b.disabled = !!job; }); const stopTask = panel.querySelector('[data-act="stop"]'); if (stopTask) stopTask.remove(); if (job) { const btn2 = document.createElement("button"); btn2.setAttribute("data-act", "stop"); btn2.textContent = "停止任务"; panel.querySelector(".swp-btns").appendChild(btn2); } } async function refreshBalance() { try { const b = await queryBalance(); const state = loadState(); state._balance = b.balance; saveState(state); if (balEl) balEl.textContent = `当前总积分:${b.balance}`; return b; } catch (e) { if (balEl) balEl.textContent = "积分查询失败:" + e.message; throw e; } } function buildPanel() { const fab = document.createElement("div"); fab.id = "swp-fab"; fab.textContent = "积分"; fab.title = "智慧教育平台每周任务积分助手(UI版)"; panel = document.createElement("div"); panel.id = "swp-panel"; panel.innerHTML = `\n