51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
/**
|
|
* 任务:每日签到
|
|
*
|
|
* 逻辑:
|
|
* 1. 找到"每日签到"任务卡片
|
|
* 2. 点击"签到"按钮
|
|
*/
|
|
|
|
const path = require('path');
|
|
const logger = require(path.join(__dirname, '..', 'utils', 'logger'));
|
|
|
|
/**
|
|
* 执行每日签到
|
|
* @param {import('playwright').Page} page - 主页面
|
|
*/
|
|
async function dailyCheckIn(page) {
|
|
logger.info('👉 执行每日签到');
|
|
|
|
// 从主页面找到"每日签到"任务卡片
|
|
const tasks = await page.locator('.novice-task-item-box').all();
|
|
let found = false;
|
|
|
|
for (const task of tasks) {
|
|
try {
|
|
const text = await task.locator('.task-card-title__label-text').innerText();
|
|
if (text.includes('每日签到')) {
|
|
const signInBtn = task.locator('button:has-text("签到")');
|
|
const isVisible = await signInBtn.isVisible().catch(() => false);
|
|
|
|
if (isVisible) {
|
|
await signInBtn.click();
|
|
logger.info('签到按钮已点击');
|
|
found = true;
|
|
} else {
|
|
logger.info('签到按钮不可见,可能已签到');
|
|
found = true;
|
|
}
|
|
break;
|
|
}
|
|
} catch (_) {
|
|
// 跳过定位失败的元素
|
|
}
|
|
}
|
|
|
|
if (!found) {
|
|
throw new Error('未找到"每日签到"任务卡片或签到按钮');
|
|
}
|
|
}
|
|
|
|
module.exports = dailyCheckIn;
|