MCPcopy Create free account
hub / github.com/Yantesoft/LinuxdoAssistant / findChatButton

Function findChatButton

linuxdo-helper.user.js:376–400  ·  view source on GitHub ↗

* 查找聊天按钮元素 * @returns {Promise } 聊天按钮元素或null

()

Source from the content-addressed store, hash-verified

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 * 查找备用插入位置

Callers 1

createSwitchIconFunction · 0.85

Calls 2

randomByJitterFunction · 0.85
waitForElementFunction · 0.85

Tested by

no test coverage detected