// Hamibot 起点读书自动化脚本
// 注意:需购买Hamibot会员才能使用云端定时功能,免费版仅支持本地运行
// 配置项
const taskBtn = "去完成";
const skipBtn = "跳过";
const closeBtn = "关闭";
const taskCount = 3;
const adWait = 20000;
const interval = 3000;
async function run() {
toast("脚本启动");
await sleep(interval);
for (let i = 0; i < taskCount; i++) {
toast(`执行第${i+1}个任务`);
// 点击任务按钮
let task = await text(taskBtn).findOne(5000);
if (!task) {
toast("任务按钮未找到,退出");
return;
}
await task.click();
await sleep(interval);
// 等待广告
await sleep(adWait);
// 点击跳过
let skip = await text(skipBtn).findOne(10000);
if (skip) {
await skip.click();
await sleep(interval);
} else {
let close = await text(closeBtn).findOne(5000);
if (close) await close.click();
}
// 返回任务页
await back();
await sleep(interval);
}
toast("任务完成");
}
run();
回答
这段代码不是有效的 Hamibot 脚本,原因如下:
- 使用了
async/await语法(如async function run()、await sleep()) - Hamibot 使用的 JavaScript 引擎是 Rhino 1.7.15,不支持 async/await
- 所有 API(如
text().findOne()、sleep())均为同步函数,无需也不支持 await
正确写法(兼容 Hamibot):
// 文档地址 https://docs.hamibot.com/
// Hamibot 起点读书自动化脚本(修正版)
const taskBtn = "去完成";
const skipBtn = "跳过";
const closeBtn = "关闭";
const taskCount = 3;
const adWait = 20000;
const interval = 3000;
function run() {
toast("脚本启动");
sleep(interval);
for (let i = 0; i < taskCount; i++) {
toast("执行第" + (i + 1) + "个任务");
// 点击任务按钮
let task = text(taskBtn).findOne(5000);
if (!task) {
toast("任务按钮未找到,退出");
return;
}
task.click();
sleep(interval);
// 等待广告
sleep(adWait);
// 点击跳过或关闭
let skip = text(skipBtn).findOne(10000);
if (skip) {
skip.click();
sleep(interval);
} else {
let close = text(closeBtn).findOne(5000);
if (close) close.click();
}
// 返回任务页
back();
sleep(interval);
}
toast("任务完成");
}
run();
ℹ️ 内容由 AI 生成,可能不准确,请注意核实