()
| 375 | let attemptCount = 0 |
| 376 | |
| 377 | function checkAndInsert() { |
| 378 | if (checkTimer) { |
| 379 | clearTimeout(checkTimer) |
| 380 | checkTimer = null |
| 381 | } |
| 382 | |
| 383 | insertCustomElement(document.querySelector(MOBILE_SELECTOR), 'beforeend') |
| 384 | const elements = document.querySelectorAll(DESKTOP_SELECTOR) |
| 385 | if (elements.length >= 2) { |
| 386 | const target = elements[elements.length - 2] |
| 387 | if (insertCustomElement(target)) { |
| 388 | console.log('插入成功,终止检测') |
| 389 | return true |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | if (attemptCount >= MAX_ATTEMPTS) { |
| 394 | console.warn(`已达到最大尝试次数 ${MAX_ATTEMPTS} 次`) |
| 395 | return false |
| 396 | } |
| 397 | |
| 398 | currentDelay = Math.min(currentDelay * 1.5, MAX_DELAY) |
| 399 | attemptCount++ |
| 400 | |
| 401 | checkTimer = setTimeout(() => { |
| 402 | checkAndInsert() |
| 403 | }, currentDelay) |
| 404 | |
| 405 | return false |
| 406 | } |
| 407 | |
| 408 | function insertCustomElement(target) { |
| 409 | if (!target?.parentNode) return false |
no test coverage detected