#91 凌枫 这段是签到的代码,在dom改变时运行
(async ()=>{
if (window.checked || window.checking) return; // 这里保证了签到中或者已经签到完成不再次触发,有其他地方写了每天凌晨自动设置 window.checked = false;
window.checking = true; // 设置签到中
let history_req = await $fetch("/api/checkin/history"); // 请求签到历史
let history = (await history_req.json())?.data;
if (!history) {
window.checking = false; // 服务器没传数据,等下一次dom变化再试
return;
}
if (history[new Date().getDay()-1].attributes.type == "R") { // 如果今天已经签到,那么设置 window.checked = true;
window.checking = false;
window.checked = true;
return;
}
let userid = (await getFlarumJsonPayload())?.session.userId; // 否则,获取userid
if (!userid) {
window.checking = false; // 一样的错误逻辑
return;
}
let req = await $fetch(`/api/users/${userid}`, { // 签到
headers: {
"content-type": "application/json; charset=UTF-8",
"x-http-method-override": "PATCH"
},
body: JSON.stringify({
"data": {
"type": "users",
"attributes": {
"allowCheckin": false,
"checkin_days_count": new Date().getDay(),
"checkin_type": "R",
"g-recaptcha-response": "" // 不完成验证码,要不然我得被砍死(
},
"id": userid.toString()
}
}),
method: "POST",
});
let data = await req.json();
if (data.data.attributes.checkin_days_count != new Date().getDay()) { // 如果请求结果的最后一次签到不是今天,则错误处理
window.checking = false;
return;
}
window.checking = false;
window.checked = true; // 签到成功
let r_history_req = await fetch("/api/checkin/history"); // 再次检查历史
let r_history = (await r_history_req.json())?.data;
if (r_history) window.customAlert(`签到成功!获得 ${r_history[new Date().getDay()-1].attributes.reward_money} NL`); // 这里实际上可以直接获取前面post结果的信息,但是再请求一次history是为了避免意外
})();
我建议检查你的系统时间是否正确,以及时区是否是 UTC + 08:00