feat: 每日积分模式与 Bark 完成提醒
- 按课时类型计分:文档 1 / 视频 3 / 音频 2 / 微课 2,每次 3 分,单日封顶 24 分;满额换类,无内容即停 - 积分计数落 localStorage,跨刷新/重启保留、跨天清零;面板与无头 TUI 都显示今日积分 - 运行器自己收尾时通过 Bark 推送今日积分、完成门数、用时和结束原因;手动停止与 --check 不推送 - 新增 --points-mode / --bark-* 参数及对应 YUN_XUE_TANG_* 环境变量 - 补充 points / notify 离线回归测试与 OpenSpec 配置 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
17217dbeb1
commit
0eb4c40629
31 files changed
+2954
-21
No files matched your search
@@ -106,17 +106,217 @@
|
||||
var LS_PENDING = "yun-xue-tang-auto-start-after-login";
|
||||
var SS_RUN_STATE = "yun-xue-tang-run-state-v3";
|
||||
var SS_SHORT_CATALOG = "yun-xue-tang-short-catalog-v1";
|
||||
var SS_POINTS_INVENTORY = "yun-xue-tang-points-inventory-v1";
|
||||
var SHORT_CATALOG_TTL = 5 * 60 * 1e3;
|
||||
var POINTS_INVENTORY_TTL = 5 * 60 * 1e3;
|
||||
var LEGACY_LS_BATCH = "yun-xue-tang-batch-v2";
|
||||
var PANEL_ID = "yun-xue-tang-panel";
|
||||
var TAG = "[云学堂助手]";
|
||||
|
||||
// src/points.js
|
||||
var POINT_RULES = [
|
||||
{ key: "doc", label: "文档", cap: 1 },
|
||||
{ key: "video", label: "视频", cap: 3 },
|
||||
{ key: "audio", label: "音频", cap: 2 },
|
||||
{ key: "micro", label: "微课", cap: 2 }
|
||||
];
|
||||
var POINTS_PER_TASK = 3;
|
||||
var MAX_DAILY_POINTS = POINT_RULES.reduce((n, r) => n + r.cap, 0) * POINTS_PER_TASK;
|
||||
var LS_POINTS_MODE = "yun-xue-tang-daily-points-mode";
|
||||
var LS_POINTS_STATE = "yun-xue-tang-daily-points-v1";
|
||||
var TYPE_MATCHERS = [
|
||||
["micro", /微课|micro/i],
|
||||
["doc", /文档|课件|ppt|document|article/i],
|
||||
["audio", /音频|audio/i],
|
||||
["video", /视频|video/i]
|
||||
];
|
||||
function detectLessonType(input) {
|
||||
input = input || {};
|
||||
const sources = [input.hash, input.fileType, input.tag];
|
||||
for (const src of sources) {
|
||||
if (!src) continue;
|
||||
const s = String(src);
|
||||
for (const pair of TYPE_MATCHERS) {
|
||||
if (pair[1].test(s)) return pair[0];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function apiTypeKey(type) {
|
||||
const n = Number(type);
|
||||
if (n === 1) return "doc";
|
||||
if (n === 2) return "video";
|
||||
if (n === 3) return "audio";
|
||||
return "";
|
||||
}
|
||||
function pointLabel(key) {
|
||||
const rule = POINT_RULES.find((r) => r.key === key);
|
||||
return rule ? rule.label : key || "未知";
|
||||
}
|
||||
function nextTarget(opts) {
|
||||
opts = opts || {};
|
||||
const isFull = typeof opts.isFull === "function" ? opts.isFull : () => false;
|
||||
const available = opts.available || {};
|
||||
for (const rule of POINT_RULES) {
|
||||
if (isFull(rule.key)) continue;
|
||||
if (rule.key === "video") {
|
||||
if (available.video !== false) return { type: "video", kind: "course" };
|
||||
continue;
|
||||
}
|
||||
if (available[rule.key]) return { type: rule.key, kind: "item" };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function pad2(n) {
|
||||
return n < 10 ? "0" + n : "" + n;
|
||||
}
|
||||
function dayKey(ms) {
|
||||
const d = new Date(ms);
|
||||
return d.getFullYear() + "-" + pad2(d.getMonth() + 1) + "-" + pad2(d.getDate());
|
||||
}
|
||||
function blankState(date) {
|
||||
const counts = {};
|
||||
for (const rule of POINT_RULES) counts[rule.key] = 0;
|
||||
return { date, counts, seen: {} };
|
||||
}
|
||||
function normalizeState(obj) {
|
||||
const state2 = blankState(obj && obj.date ? String(obj.date) : "");
|
||||
for (const rule of POINT_RULES) {
|
||||
const n = Number(obj && obj.counts && obj.counts[rule.key]);
|
||||
state2.counts[rule.key] = Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
|
||||
}
|
||||
if (obj && obj.seen && typeof obj.seen === "object") state2.seen = obj.seen;
|
||||
return state2;
|
||||
}
|
||||
function createPointsTracker(opts = {}) {
|
||||
const now = opts.now || (() => Date.now());
|
||||
const storage = opts.storage !== void 0 ? opts.storage : typeof localStorage !== "undefined" ? localStorage : null;
|
||||
const storageKey = opts.storageKey || LS_POINTS_STATE;
|
||||
let enabled = opts.enabled !== void 0 ? !!opts.enabled : true;
|
||||
let state2 = load();
|
||||
rollover();
|
||||
function load() {
|
||||
try {
|
||||
const raw = storage && storage.getItem(storageKey);
|
||||
if (!raw) return blankState(dayKey(now()));
|
||||
return normalizeState(JSON.parse(raw));
|
||||
} catch (e) {
|
||||
return blankState(dayKey(now()));
|
||||
}
|
||||
}
|
||||
function save() {
|
||||
try {
|
||||
if (storage) storage.setItem(storageKey, JSON.stringify(state2));
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
function rollover() {
|
||||
const today = dayKey(now());
|
||||
if (state2.date === today) return false;
|
||||
state2 = blankState(today);
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
function ruleOf(key) {
|
||||
return POINT_RULES.find((r) => r.key === key) || null;
|
||||
}
|
||||
function count(key) {
|
||||
return state2.counts[key] || 0;
|
||||
}
|
||||
function cap(key) {
|
||||
const rule = ruleOf(key);
|
||||
return rule ? rule.cap : 0;
|
||||
}
|
||||
function isFull(key) {
|
||||
return count(key) >= cap(key);
|
||||
}
|
||||
function remaining(key) {
|
||||
return Math.max(0, cap(key) - count(key));
|
||||
}
|
||||
function record(key, lessonId) {
|
||||
rollover();
|
||||
if (!enabled) return false;
|
||||
if (!ruleOf(key) || isFull(key)) return false;
|
||||
if (lessonId) {
|
||||
if (state2.seen[lessonId]) return false;
|
||||
state2.seen[lessonId] = 1;
|
||||
}
|
||||
state2.counts[key] = count(key) + 1;
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
function totalPoints() {
|
||||
let total = 0;
|
||||
for (const rule of POINT_RULES) {
|
||||
total += Math.min(count(rule.key), rule.cap) * POINTS_PER_TASK;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
function maxPoints() {
|
||||
return MAX_DAILY_POINTS;
|
||||
}
|
||||
function allFull() {
|
||||
return POINT_RULES.every((rule) => isFull(rule.key));
|
||||
}
|
||||
function done(available) {
|
||||
return POINT_RULES.every((rule) => isFull(rule.key) || !!available && available[rule.key] === false);
|
||||
}
|
||||
function progress() {
|
||||
return POINT_RULES.map((rule) => ({
|
||||
key: rule.key,
|
||||
label: rule.label,
|
||||
count: Math.min(count(rule.key), rule.cap),
|
||||
cap: rule.cap
|
||||
}));
|
||||
}
|
||||
function summary() {
|
||||
const parts = progress().map((p) => p.label + p.count + "/" + p.cap);
|
||||
return "今日积分 " + totalPoints() + "/" + maxPoints() + " · " + parts.join(" ");
|
||||
}
|
||||
function snapshot() {
|
||||
return {
|
||||
enabled,
|
||||
date: state2.date,
|
||||
total: totalPoints(),
|
||||
max: maxPoints(),
|
||||
progress: progress(),
|
||||
text: summary()
|
||||
};
|
||||
}
|
||||
function setEnabled(on) {
|
||||
enabled = !!on;
|
||||
if (enabled) rollover();
|
||||
}
|
||||
function isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
return {
|
||||
record,
|
||||
count,
|
||||
cap,
|
||||
isFull,
|
||||
remaining,
|
||||
totalPoints,
|
||||
maxPoints,
|
||||
allFull,
|
||||
done,
|
||||
progress,
|
||||
summary,
|
||||
snapshot,
|
||||
setEnabled,
|
||||
isEnabled,
|
||||
rollover
|
||||
};
|
||||
}
|
||||
|
||||
// src/state.js
|
||||
var state = {
|
||||
autoPlayEnabled: true,
|
||||
// 当前课程自动连播(自己点开的课)
|
||||
preferShortCourses: CFG.preferShortCourses
|
||||
preferShortCourses: CFG.preferShortCourses,
|
||||
// 列表刷课时优先后时长更短的课程(正序)
|
||||
pointsEnabled: true
|
||||
// 每日积分模式:按课时类型计分并封顶
|
||||
};
|
||||
try {
|
||||
state.autoPlayEnabled = localStorage.getItem(LS_ENABLED) !== "0";
|
||||
@@ -127,6 +327,11 @@
|
||||
if (v === "0" || v === "1") state.preferShortCourses = v === "1";
|
||||
} catch (e) {
|
||||
}
|
||||
try {
|
||||
state.pointsEnabled = localStorage.getItem(LS_POINTS_MODE) !== "0";
|
||||
} catch (e) {
|
||||
}
|
||||
var points = createPointsTracker({ enabled: state.pointsEnabled });
|
||||
var PHASE_ENTERING = "entering";
|
||||
var PHASE_LEARNING = "learning";
|
||||
var PHASE_IDLE = "idle";
|
||||
@@ -352,8 +557,17 @@
|
||||
shortJumpAt: 0,
|
||||
shortNoVmSince: 0,
|
||||
shortWarnedAt: 0,
|
||||
retryStatusSec: -1
|
||||
retryStatusSec: -1,
|
||||
// 「等待重试」提示上次写出的剩余秒数(只在变化时刷状态)
|
||||
// 每日积分模式:当前课时的类型缓存(课时 id → doc/video/audio/micro),
|
||||
// 以及文档/音频/微课的单条库存(视频靠课程里的课时,不单独存)
|
||||
lessonTypes: {},
|
||||
pointsInventory: null,
|
||||
pointsInventoryLoading: false,
|
||||
pointsInventoryFailedAt: 0,
|
||||
pointsFetchStartedAt: 0,
|
||||
pointsNoVmSince: 0,
|
||||
pointsWarnedAt: 0
|
||||
};
|
||||
function invalidateShortCatalog() {
|
||||
R.shortCatalog = null;
|
||||
@@ -368,6 +582,7 @@
|
||||
function resetCourseRuntime() {
|
||||
R.lastLessonKey = "";
|
||||
R.doneLatchKey = "";
|
||||
R.lessonTypes = {};
|
||||
R.lastSummary = null;
|
||||
R.lastCountdown = null;
|
||||
R.lastProgressAt = Date.now();
|
||||
@@ -548,7 +763,7 @@
|
||||
return "other";
|
||||
}
|
||||
function mediaPage() {
|
||||
return /^#\/(?:video|audio|ppt|document|article)\/play(?:[?/]|$)/i.test(location.hash || "");
|
||||
return /^#\/(?:video|audio|ppt|document|article|micro|microcourse)\/play(?:[?/]|$)/i.test(location.hash || "");
|
||||
}
|
||||
function goToList(force) {
|
||||
if (!force && Date.now() - R.lastGoListAt < 5e3) return;
|
||||
@@ -880,6 +1095,9 @@
|
||||
var labelBatch = null;
|
||||
var labelShort = null;
|
||||
var cbPreferShort = null;
|
||||
var labelPoints = null;
|
||||
var cbPoints = null;
|
||||
var pointsEl = null;
|
||||
var cbAuto = null;
|
||||
var loginBox = null;
|
||||
var loginUserEl = null;
|
||||
@@ -921,12 +1139,19 @@
|
||||
}
|
||||
if (cbAuto) cbAuto.checked = state.autoPlayEnabled;
|
||||
if (cbPreferShort) cbPreferShort.checked = state.preferShortCourses;
|
||||
if (cbPoints) cbPoints.checked = state.pointsEnabled;
|
||||
if (pointsEl) {
|
||||
pointsEl.style.display = state.pointsEnabled ? "block" : "none";
|
||||
pointsEl.textContent = state.pointsEnabled ? points.summary() : "";
|
||||
}
|
||||
const onLogin = isLoginPage();
|
||||
if (loginBox) loginBox.style.display = onLogin ? "block" : "none";
|
||||
if (labelAuto) labelAuto.style.display = onLogin ? "none" : "flex";
|
||||
if (labelBatch) labelBatch.style.display = onLogin ? "none" : "flex";
|
||||
if (labelShort) labelShort.style.display = onLogin ? "none" : "flex";
|
||||
if (labelPoints) labelPoints.style.display = onLogin ? "none" : "flex";
|
||||
if (statsEl) statsEl.style.display = onLogin ? "none" : "block";
|
||||
if (pointsEl) pointsEl.style.display = onLogin ? "none" : state.pointsEnabled ? "block" : "none";
|
||||
if (btnOne) {
|
||||
const onCourse = route() === "course" && !!S.activeCourse;
|
||||
btnOne.textContent = onLogin ? "一键登录并刷课" : onCourse && S.batchRunning ? "停止刷课" : "一键刷课";
|
||||
@@ -1131,6 +1356,27 @@
|
||||
});
|
||||
labelShort.appendChild(cbPreferShort);
|
||||
labelShort.appendChild(document.createTextNode("优先短课程(时长正序)"));
|
||||
labelPoints = document.createElement("label");
|
||||
labelPoints.style.cssText = LABEL_CSS;
|
||||
cbPoints = document.createElement("input");
|
||||
cbPoints.type = "checkbox";
|
||||
cbPoints.id = "yun-xue-tang-points-enabled";
|
||||
cbPoints.checked = state.pointsEnabled;
|
||||
cbPoints.title = "按课时类型计分:文档1 / 视频3 / 音频2 / 微课2,每天最多 24 分";
|
||||
cbPoints.addEventListener("change", function() {
|
||||
state.pointsEnabled = cbPoints.checked;
|
||||
points.setEnabled(state.pointsEnabled);
|
||||
try {
|
||||
localStorage.setItem(LS_POINTS_MODE, state.pointsEnabled ? "1" : "0");
|
||||
} catch (e) {
|
||||
}
|
||||
R.pointsInventory = null;
|
||||
R.pointsInventoryFailedAt = 0;
|
||||
setStatus(state.pointsEnabled ? "已开启每日积分模式:" + points.summary() : "已关闭每日积分模式,恢复普通刷课");
|
||||
updatePanel();
|
||||
});
|
||||
labelPoints.appendChild(cbPoints);
|
||||
labelPoints.appendChild(document.createTextNode("每日积分模式(凑满 24 分就停)"));
|
||||
statusEl = document.createElement("div");
|
||||
statusEl.id = "yun-xue-tang-status";
|
||||
statusEl.textContent = "待机";
|
||||
@@ -1138,6 +1384,9 @@
|
||||
statsEl = document.createElement("div");
|
||||
statsEl.id = "yun-xue-tang-stats";
|
||||
statsEl.style.cssText = "margin-top:2px;color:#aaa;";
|
||||
pointsEl = document.createElement("div");
|
||||
pointsEl.id = "yun-xue-tang-points";
|
||||
pointsEl.style.cssText = "margin-top:2px;color:#8ee6c0;";
|
||||
const hint = document.createElement("div");
|
||||
hint.textContent = "真实播放计时 · 保持窗口可见";
|
||||
hint.style.cssText = "margin-top:6px;color:#777;font-size:11px;";
|
||||
@@ -1152,8 +1401,10 @@
|
||||
box.appendChild(labelAuto);
|
||||
box.appendChild(labelBatch);
|
||||
box.appendChild(labelShort);
|
||||
box.appendChild(labelPoints);
|
||||
box.appendChild(statusEl);
|
||||
box.appendChild(statsEl);
|
||||
box.appendChild(pointsEl);
|
||||
box.appendChild(hint);
|
||||
box.appendChild(footer);
|
||||
document.documentElement.appendChild(box);
|
||||
@@ -2116,6 +2367,229 @@
|
||||
setStatus("短课程优先暂不可用,先按当前页时长排序");
|
||||
}
|
||||
}
|
||||
function emptyPointsInventory() {
|
||||
return { at: Date.now(), doc: [], audio: [], micro: [] };
|
||||
}
|
||||
function pointsInventoryCacheKey(vm) {
|
||||
return String(vm && vm.collegeId || localStorage.getItem("orgId") || "");
|
||||
}
|
||||
function readPointsInventory(key) {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(SS_POINTS_INVENTORY);
|
||||
if (!raw) return null;
|
||||
const obj = JSON.parse(raw);
|
||||
if (!obj || obj.key !== key || !obj.doc || !obj.audio || !obj.micro) return null;
|
||||
if (Date.now() - (obj.at || 0) > POINTS_INVENTORY_TTL) return null;
|
||||
return obj;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function writePointsInventory(inv, key) {
|
||||
if (!inv) return;
|
||||
try {
|
||||
sessionStorage.setItem(SS_POINTS_INVENTORY, JSON.stringify({
|
||||
key,
|
||||
at: inv.at,
|
||||
doc: inv.doc,
|
||||
audio: inv.audio,
|
||||
micro: inv.micro
|
||||
}));
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
function routeForFileType(fileType) {
|
||||
const s = String(fileType || "").toLowerCase();
|
||||
if (s === "audio") return "audio/play";
|
||||
if (s === "video") return "video/play";
|
||||
if (s === "document" || s === "doc") return "document/play";
|
||||
if (s === "article") return "article/play";
|
||||
if (/micro/.test(s)) return "micro/play";
|
||||
return "ppt/play";
|
||||
}
|
||||
async function fetchPointsInventory(vm) {
|
||||
const req = shortCatalogRequest(vm);
|
||||
const baseBody = JSON.parse(req.body);
|
||||
const api = shortApiBase();
|
||||
const inv = emptyPointsInventory();
|
||||
const seen = /* @__PURE__ */ new Set();
|
||||
const types = [1, 3, 4, 5, 6, 7, 8];
|
||||
let failed = 0;
|
||||
for (const type of types) {
|
||||
let list = null;
|
||||
try {
|
||||
const body = JSON.stringify(Object.assign({}, baseBody, { type: String(type) }));
|
||||
const res = await fetch(api + "?limit=50&offset=0&orderType=desc&orderBy=createTime", {
|
||||
method: "POST",
|
||||
headers: req.headers,
|
||||
body
|
||||
});
|
||||
if (!res.ok) throw new Error("HTTP " + res.status);
|
||||
const json = await res.json();
|
||||
list = Array.isArray(json && json.datas) ? json.datas : [];
|
||||
} catch (e) {
|
||||
failed++;
|
||||
continue;
|
||||
}
|
||||
for (const item of list) {
|
||||
if (!item || !item.title) continue;
|
||||
if (Number(item.status) === 2 || item.studyComplete === 1 || item.studyComplete === true) continue;
|
||||
const key = apiTypeKey(item.type) || detectLessonType({ fileType: item.fileType });
|
||||
if (!key || key === "video") continue;
|
||||
const id = item.id ? String(item.id) : "";
|
||||
if (!id || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
inv[key].push({
|
||||
id,
|
||||
title: norm(item.title),
|
||||
fileType: item.fileType || "",
|
||||
route: routeForFileType(item.fileType),
|
||||
hours: Number(item.studyHours) || 0
|
||||
});
|
||||
}
|
||||
}
|
||||
if (failed >= types.length) throw new Error("积分库存接口全部失败");
|
||||
return inv;
|
||||
}
|
||||
function ensurePointsInventory() {
|
||||
if (!state.pointsEnabled) return "off";
|
||||
if (R.pointsInventory) return "ready";
|
||||
const vm = listVm();
|
||||
if (!vm) {
|
||||
if (!R.pointsNoVmSince) R.pointsNoVmSince = Date.now();
|
||||
if (Date.now() - R.pointsNoVmSince > 5e3) {
|
||||
R.pointsInventory = emptyPointsInventory();
|
||||
R.pointsInventoryFailedAt = Date.now();
|
||||
if (Date.now() - (R.pointsWarnedAt || 0) > 1e4) {
|
||||
R.pointsWarnedAt = Date.now();
|
||||
console.warn(TAG, "未找到课程列表组件,积分库存按「只有视频课时」处理");
|
||||
}
|
||||
return "failed";
|
||||
}
|
||||
return "loading";
|
||||
}
|
||||
R.pointsNoVmSince = 0;
|
||||
if (R.pointsInventoryLoading) {
|
||||
if (Date.now() - R.pointsFetchStartedAt > 2e4) {
|
||||
R.pointsInventoryLoading = false;
|
||||
R.pointsInventory = emptyPointsInventory();
|
||||
R.pointsInventoryFailedAt = Date.now();
|
||||
return "failed";
|
||||
}
|
||||
return "loading";
|
||||
}
|
||||
if (R.pointsInventoryFailedAt && Date.now() - R.pointsInventoryFailedAt < 3e4) return "failed";
|
||||
const key = pointsInventoryCacheKey(vm);
|
||||
const cached = readPointsInventory(key);
|
||||
if (cached) {
|
||||
R.pointsInventory = cached;
|
||||
return "ready";
|
||||
}
|
||||
R.pointsInventoryLoading = true;
|
||||
R.pointsFetchStartedAt = Date.now();
|
||||
setStatus("正在读取文档/音频/微课库存…");
|
||||
fetchPointsInventory(vm).then(function(inv) {
|
||||
R.pointsInventoryLoading = false;
|
||||
R.pointsInventory = inv;
|
||||
writePointsInventory(inv, key);
|
||||
const parts = POINT_RULES.filter(function(r) {
|
||||
return r.key !== "video";
|
||||
}).map(function(r) {
|
||||
return r.label + " " + (inv[r.key] && inv[r.key].length || 0) + " 条";
|
||||
});
|
||||
console.log(TAG, "积分库存已就绪:" + parts.join(","));
|
||||
updatePanel();
|
||||
}).catch(function(e) {
|
||||
R.pointsInventoryLoading = false;
|
||||
R.pointsInventory = emptyPointsInventory();
|
||||
R.pointsInventoryFailedAt = Date.now();
|
||||
if (Date.now() - (R.pointsWarnedAt || 0) > 1e4) {
|
||||
R.pointsWarnedAt = Date.now();
|
||||
console.warn(TAG, "读取积分库存失败,按「只有视频课时」处理:", e && e.message ? e.message : e);
|
||||
}
|
||||
});
|
||||
return "loading";
|
||||
}
|
||||
function nextPointsItem(type) {
|
||||
const inv = R.pointsInventory;
|
||||
const arr = inv && inv[type] || [];
|
||||
return arr.find(function(item) {
|
||||
if (!item || !item.title) return false;
|
||||
if (S.completedTitles[item.title] || courseSkipped(item.title)) return false;
|
||||
return true;
|
||||
}) || null;
|
||||
}
|
||||
function pointsAvailability(videoAvailable) {
|
||||
return {
|
||||
doc: !!nextPointsItem("doc"),
|
||||
video: videoAvailable !== false,
|
||||
audio: !!nextPointsItem("audio"),
|
||||
micro: !!nextPointsItem("micro")
|
||||
};
|
||||
}
|
||||
function pointsDone() {
|
||||
if (!state.pointsEnabled) return false;
|
||||
return points.done(pointsAvailability());
|
||||
}
|
||||
function pointsTarget() {
|
||||
return nextTarget({
|
||||
isFull: function(key) {
|
||||
return points.isFull(key);
|
||||
},
|
||||
available: pointsAvailability()
|
||||
});
|
||||
}
|
||||
function leaveForPoints(reason) {
|
||||
if (S.activeCourse) {
|
||||
S.activeCourse = null;
|
||||
S.coursePhase = PHASE_IDLE;
|
||||
}
|
||||
S.awaitingListReturn = true;
|
||||
saveRunState();
|
||||
setStatus(reason);
|
||||
console.log(TAG, reason);
|
||||
goToList(true);
|
||||
}
|
||||
function pointsAfterLesson(type) {
|
||||
if (!state.pointsEnabled) return false;
|
||||
if (!R.pointsInventory) {
|
||||
ensurePointsInventory();
|
||||
return false;
|
||||
}
|
||||
if (pointsDone()) {
|
||||
leaveForPoints("今日积分:可用内容已学完(" + points.summary() + ")");
|
||||
return true;
|
||||
}
|
||||
if (type && points.isFull(type)) {
|
||||
const target = pointsTarget();
|
||||
if (target && target.type !== type) {
|
||||
leaveForPoints("“" + pointLabel(type) + "”已满额,切换学习“" + pointLabel(target.type) + "”");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function startStandalone(item, type) {
|
||||
if (!item) return false;
|
||||
R.lastCardClickAt = Date.now();
|
||||
R.shortJumpAt = 0;
|
||||
S.activeCourse = {
|
||||
title: item.title,
|
||||
id: item.id,
|
||||
startedAt: Date.now(),
|
||||
standalone: true,
|
||||
pointType: type
|
||||
};
|
||||
S.coursePhase = PHASE_ENTERING;
|
||||
S.awaitingListReturn = false;
|
||||
resetCourseRuntime();
|
||||
saveRunState();
|
||||
const label = pointLabel(type);
|
||||
setStatus("进入" + label + ":" + truncate(item.title, 26));
|
||||
console.log(TAG, "进入" + label, item.title, "(积分模式)");
|
||||
location.href = location.origin + "/kng/#/" + item.route + "?kngId=" + encodeURIComponent(item.id);
|
||||
return true;
|
||||
}
|
||||
function pendingShortItems() {
|
||||
const cat = R.shortCatalog;
|
||||
if (!cat) return [];
|
||||
@@ -2328,6 +2802,29 @@
|
||||
return;
|
||||
}
|
||||
R.retryStatusSec = -1;
|
||||
if (state.pointsEnabled) {
|
||||
const invStatus = ensurePointsInventory();
|
||||
if (invStatus === "loading") return;
|
||||
if (pointsDone()) {
|
||||
const text = points.summary();
|
||||
console.log(TAG, "今日积分:可用内容已学完", text);
|
||||
stopBatch("今日积分:可用内容已学完(" + text + ")");
|
||||
return;
|
||||
}
|
||||
const target = pointsTarget();
|
||||
if (!target) {
|
||||
stopBatch("今日积分任务:剩余类型都没有可学内容");
|
||||
return;
|
||||
}
|
||||
if (target.kind === "item") {
|
||||
const item = nextPointsItem(target.type);
|
||||
if (item) {
|
||||
if (Date.now() - R.lastCardClickAt < 3e3) return;
|
||||
startStandalone(item, target.type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
const pending = cards.filter((c) => {
|
||||
if (!c.title) return false;
|
||||
if (/已学完|已完成|已学习/.test(c.status)) return false;
|
||||
@@ -2687,6 +3184,33 @@
|
||||
}
|
||||
|
||||
// src/course.js
|
||||
function pointLessonId(key) {
|
||||
const courseId = S.activeCourse && S.activeCourse.id || courseIdFromUrl() || "";
|
||||
return courseId + "|" + (key || "media");
|
||||
}
|
||||
function rememberLessonType(key) {
|
||||
if (!state.pointsEnabled) return;
|
||||
const li = lessonActiveLi();
|
||||
const tagEl = li ? li.querySelector(".tag-type") : null;
|
||||
const type = detectLessonType({
|
||||
tag: tagEl ? textOf(tagEl) : "",
|
||||
hash: location.hash
|
||||
});
|
||||
if (!type) return;
|
||||
R.lessonType = type;
|
||||
R.lessonTypes[pointLessonId(key)] = type;
|
||||
}
|
||||
function recordLessonPoint(key) {
|
||||
if (!state.pointsEnabled) return "";
|
||||
const id = pointLessonId(key);
|
||||
const type = R.lessonTypes[id] || R.lessonType || detectLessonType({ hash: location.hash });
|
||||
if (!type) return "";
|
||||
if (!points.record(type, id)) return "";
|
||||
const text = points.snapshot().text;
|
||||
console.log(TAG, "积分 +3:" + pointLabel(type) + "(" + text + ")");
|
||||
setStatus("积分 +3:" + pointLabel(type) + "(" + text + ")");
|
||||
return type;
|
||||
}
|
||||
function courseTick() {
|
||||
R.listWithCurrentSince = 0;
|
||||
if (!S.activeCourse) {
|
||||
@@ -2741,6 +3265,7 @@
|
||||
}
|
||||
}
|
||||
if (!examPhase() && !isSummaryComplete() && enterPendingExamLesson()) return;
|
||||
rememberLessonType(readActiveLessonKey());
|
||||
const summary = readSummary();
|
||||
const prevSummaryX = R.lastSummary ? R.lastSummary.x : -1;
|
||||
if (summary) {
|
||||
@@ -2748,6 +3273,7 @@
|
||||
const confirmed = !!(R.lastSummary && R.lastSummary.complete);
|
||||
R.lastSummary = summary;
|
||||
if (confirmed) {
|
||||
recordLessonPoint(R.waitLessonKey || R.lastLessonKey);
|
||||
completeCurrent();
|
||||
return;
|
||||
}
|
||||
@@ -2759,6 +3285,8 @@
|
||||
const prevKey = R.lastLessonKey;
|
||||
const curKey = readActiveLessonKey();
|
||||
R.lastSummary = summary;
|
||||
const pointType = !isMedia && summary.kind !== "percent" ? recordLessonPoint(prevKey) : "";
|
||||
if (pointType && pointsAfterLesson(pointType)) return;
|
||||
if (!isMedia && summary.kind !== "percent" && (!prevKey || curKey === prevKey)) {
|
||||
setStatus("本节已记录,切换下一节…");
|
||||
advanceLesson();
|
||||
@@ -2836,6 +3364,7 @@
|
||||
}
|
||||
R.waitStart = 0;
|
||||
R.lastProgressAt = Date.now();
|
||||
recordLessonPoint(R.waitLessonKey || R.lastLessonKey);
|
||||
completeCurrent();
|
||||
return;
|
||||
}
|
||||
@@ -2844,15 +3373,18 @@
|
||||
R.lastLessonKey = newKey;
|
||||
R.doneLatchKey = "";
|
||||
R.lastProgressAt = Date.now();
|
||||
const pointType = recordLessonPoint(R.waitLessonKey);
|
||||
if (pointType && pointsAfterLesson(pointType)) return;
|
||||
setStatus("已自动进入下一节");
|
||||
return;
|
||||
}
|
||||
if (!isMedia && s2 && s2.x > R.waitSummaryX) {
|
||||
R.waitStart = 0;
|
||||
R.lastProgressAt = Date.now();
|
||||
const pointType = recordLessonPoint(R.waitLessonKey || R.lastLessonKey);
|
||||
if (s2.complete) {
|
||||
completeCurrent();
|
||||
} else {
|
||||
} else if (!pointType || !pointsAfterLesson(pointType)) {
|
||||
advanceLesson();
|
||||
}
|
||||
return;
|
||||
@@ -2924,6 +3456,7 @@
|
||||
}
|
||||
const s = readSummary();
|
||||
if (s && s.complete) {
|
||||
recordLessonPoint(R.waitLessonKey || R.lastLessonKey);
|
||||
completeCurrent();
|
||||
} else {
|
||||
setStatus("没有找到下一节,等待课程完成…");
|
||||
@@ -3066,6 +3599,7 @@
|
||||
S,
|
||||
R,
|
||||
state,
|
||||
points,
|
||||
tick: tick2,
|
||||
save: saveRunState,
|
||||
flush: flushRunState,
|
||||
@@ -3112,6 +3646,12 @@
|
||||
startCourse,
|
||||
jumpToPage,
|
||||
nextPage,
|
||||
ensurePointsInventory,
|
||||
pointsAvailability,
|
||||
pointsDone,
|
||||
pointsTarget,
|
||||
pointsAfterLesson,
|
||||
startStandalone,
|
||||
listTick,
|
||||
courseTick,
|
||||
manualCourseTick,
|
||||
|
||||
Reference in new issue
Block a user