feat: expand toolbox and add math games
CI / test (pull_request) Canceled after 13s

This commit is contained in:
2026-08-09 01:52:35 +08:00
parent b99a22fc06
commit 6cd155ef05
7 changed files with 1216 additions and 35 deletions
+39 -18
View File
@@ -638,6 +638,26 @@ async function loadProfile() {
metrics.append(item);
});
root.append(heading, pet, metrics);
if (profile.recent_games?.length) {
const gameTitle = document.createElement("h3");
gameTitle.className = "profile-subtitle";
gameTitle.textContent = "最近数学玩法";
const gameList = document.createElement("div");
gameList.className = "profile-game-list";
profile.recent_games.forEach((game) => {
const item = document.createElement("div");
const name = document.createElement("b");
name.textContent = `${game.label} · ${game.difficulty}`;
const detail = document.createElement("span");
detail.textContent =
game.status === "completed"
? `${game.score} 分 · ${(game.duration_ms / 1000).toFixed(1)}`
: "进行中";
item.append(name, detail);
gameList.append(item);
});
root.append(gameTitle, gameList);
}
} catch (error) {
root.textContent = error.message;
}
@@ -673,10 +693,20 @@ function evaluateExpression(source, variables = {}) {
sin: Math.sin,
cos: Math.cos,
tan: Math.tan,
asin: Math.asin,
acos: Math.acos,
atan: Math.atan,
sinh: Math.sinh,
cosh: Math.cosh,
tanh: Math.tanh,
sqrt: Math.sqrt,
log: Math.log10,
ln: Math.log,
exp: Math.exp,
abs: Math.abs,
floor: Math.floor,
ceil: Math.ceil,
round: Math.round,
};
const skip = () => {
@@ -880,7 +910,7 @@ function switchTool(tool) {
$$(".tool-workspace").forEach((workspace) => {
workspace.classList.toggle("active", workspace.id === `tool-${tool}`);
});
if (tool === "graph") window.setTimeout(drawGraph, 30);
window.HuluToolbox?.activate(tool);
}
async function saveFormula() {
@@ -906,24 +936,9 @@ function bindUI() {
$$(".tool-card").forEach((button) => {
button.addEventListener("click", () => switchTool(button.dataset.tool));
});
$("#calc-run").addEventListener("click", runCalculator);
$("#calc-input").addEventListener("keydown", (event) => {
if (event.key === "Enter") runCalculator();
});
$$("[data-calc-example]").forEach((button) => {
button.addEventListener("click", () => {
$("#calc-input").value = button.dataset.calcExample;
runCalculator();
});
});
$("#symbol-search").addEventListener("input", (event) => {
renderSymbols(event.target.value);
});
$("#graph-run").addEventListener("click", drawGraph);
$("#graph-range").addEventListener("input", drawGraph);
$("#graph-expression").addEventListener("keydown", (event) => {
if (event.key === "Enter") drawGraph();
});
$$(".ability-node").forEach((button) => {
button.addEventListener("click", () => {
state.videoAbility =
@@ -980,9 +995,15 @@ function bindUI() {
async function boot() {
bindUI();
window.HuluToolbox?.init();
renderSymbols();
runCalculator();
await Promise.all([loadUser(), loadStories(), loadContests(), loadContent()]);
await Promise.all([
loadUser(),
loadStories(),
loadContests(),
loadContent(),
window.HuluGames?.load(),
]);
}
boot();