* 查找聊天按钮元素 * @returns {Promise } 聊天按钮元素或null
()
| 374 | * @returns {Promise<HTMLElement|null>} 聊天按钮元素或null |
| 375 | */ |
| 376 | async function findChatButton() { |
| 377 | try { |
| 378 | const timeout = randomByJitter( |
| 379 | ELEMENT_WAIT_TIMEOUT, |
| 380 | RANDOM_DELAY_CONFIG.waitForElementJitter, |
| 381 | 800 |
| 382 | ); |
| 383 | |
| 384 | const chatButton = await Promise.race([ |
| 385 | waitForElement(SELECTORS.chatButton), |
| 386 | new Promise((_, reject) => |
| 387 | setTimeout(() => reject(new Error('timeout')), timeout) |
| 388 | ) |
| 389 | ]).catch(() => null); |
| 390 | |
| 391 | if (chatButton) { |
| 392 | return chatButton; |
| 393 | } |
| 394 | } catch (e) { |
| 395 | // 忽略错误,继续尝试直接查找 |
| 396 | } |
| 397 | |
| 398 | return document.querySelector(SELECTORS.chatButton) || |
| 399 | document.querySelector(SELECTORS.chatLink)?.closest('li'); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * 查找备用插入位置 |
no test coverage detected