feat: 添加邮件刷新和收件箱链接查找功能,并增加相关测试用例

This commit is contained in:
QLHazyCoder
2026-04-18 12:17:23 +08:00
parent 033e76a16f
commit 7290649930
2 changed files with 276 additions and 3 deletions
+55 -3
View File
@@ -64,6 +64,13 @@ const MAIL_ITEM_SELECTORS = [
'[class*="list-item"]',
'li[class*="mail"]',
];
const MAIL_REFRESH_SELECTOR = '[class*="refresh"], [title*="鍒锋柊"], [aria-label*="鍒锋柊"], [class*="Refresh"]';
const MAIL_INBOX_SELECTORS = [
'a[href*="mailList"]',
'[class*="inbox"]',
'[class*="Inbox"]',
'[title*="鏀朵欢绠?]',
];
function findMailItems() {
for (const selector of MAIL_ITEM_SELECTORS) {
@@ -75,6 +82,20 @@ function findMailItems() {
return [];
}
function findRefreshButton() {
return document.querySelector(MAIL_REFRESH_SELECTOR);
}
function findInboxLink() {
for (const selector of MAIL_INBOX_SELECTORS) {
const node = document.querySelector(selector);
if (node) {
return node;
}
}
return null;
}
function getMailItemText(item) {
if (!item) return '';
const contentCell = item.querySelector('td.content, .content, .mail-content');
@@ -272,6 +293,37 @@ async function sleepRandom(minMs, maxMs = minMs) {
await sleep(duration);
}
async function returnToInbox() {
if (findMailItems().length > 0) {
return true;
}
const inboxLink = findInboxLink();
if (!inboxLink) {
return false;
}
simulateClick(inboxLink);
for (let attempt = 0; attempt < 20; attempt += 1) {
await sleep(250);
if (findMailItems().length > 0) {
return true;
}
}
return false;
}
async function openMailAndGetMessageText(item) {
simulateClick(item);
try {
await sleepRandom(1200, 2200);
return document.body?.textContent || '';
} finally {
await returnToInbox();
}
}
async function refreshInbox() {
const refreshBtn = document.querySelector(
'[class*="refresh"], [title*="刷新"], [aria-label*="刷新"], [class*="Refresh"]'
@@ -318,6 +370,7 @@ async function handlePollEmail(step, payload) {
}
if (initialItems.length === 0) {
await returnToInbox();
await refreshInbox();
await sleep(2000);
initialItems = findMailItems();
@@ -337,6 +390,7 @@ async function handlePollEmail(step, payload) {
log(`步骤 ${step}:正在轮询 2925 邮箱,第 ${attempt}/${maxAttempts}`);
if (attempt > 1) {
await returnToInbox();
await refreshInbox();
await sleepRandom(900, 1500);
}
@@ -392,9 +446,7 @@ async function handlePollEmail(step, payload) {
return { ok: true, code, emailTimestamp: Date.now() };
}
simulateClick(item);
await sleepRandom(1200, 2200);
const openedText = document.body?.textContent || '';
const openedText = await openMailAndGetMessageText(item);
const bodyCode = extractVerificationCode(openedText, strictChatGPTCodeOnly);
const openedTargetState = getTargetEmailMatchState(openedText, targetEmail);
if (targetEmail && openedTargetState.hasExplicitEmail && !openedTargetState.matches) {