DeepSeek繁忙自动点击重试

DeepSeek提示繁忙,自动点击重试,并显示操作状态通知

目前為 2025-02-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         DeepSeek繁忙自动点击重试
// @namespace    http://tampermonkey.net/
// @version      2025-02-12
// @license      MIT
// @description  DeepSeek提示繁忙,自动点击重试,并显示操作状态通知
// @author       Dingning
// @include      *://chat.deepseek.com/*
// @icon         https://registry.npmmirror.com/@lobehub/icons-static-png/latest/files/dark/deepseek-color.png
// @grant        none
// ==/UserScript==

;(function () {
  'use strict'

  // 创建通知容器
  const createNotificationContainer = () => {
    const container = document.createElement('div')
    container.id = 'retry-notifications'
    container.style.cssText = `
          position: fixed;
          top: 20px;
          right: 20px;
          z-index: 10000;
          display: flex;
          flex-direction: column;
          gap: 10px;
          max-width: 300px;
      `
    document.body.appendChild(container)
    return container
  }

  // 创建单个通知
  const createNotification = (message, type = 'info') => {
    const notification = document.createElement('div')
    notification.className = `retry-notification ${type}`
    notification.style.cssText = `
          padding: 12px 16px;
          background: white;
          border-radius: 8px;
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
          font-size: 14px;
          color: #333;
          opacity: 0;
          transform: translateX(100%);
          transition: all 0.3s ease;
          display: flex;
          align-items: center;
          gap: 8px;
      `

    // 添加图标
    const icon = document.createElement('span')
    icon.style.cssText = `
          font-size: 16px;
          font-weight: bold;
      `

    switch (type) {
      case 'success':
        icon.textContent = '✅'
        notification.style.borderLeft = '4px solid #52c41a'
        break
      case 'warning':
        icon.textContent = '⚠️'
        notification.style.borderLeft = '4px solid #faad14'
        break
      default:
        icon.textContent = 'ℹ️'
        notification.style.borderLeft = '4px solid #1890ff'
    }

    notification.appendChild(icon)

    const text = document.createElement('span')
    text.textContent = message
    notification.appendChild(text)

    // 添加到容器
    const container =
      document.getElementById('retry-notifications') ||
      createNotificationContainer()
    container.appendChild(notification)

    // 触发动画
    setTimeout(() => {
      notification.style.opacity = '1'
      notification.style.transform = 'translateX(0)'
    }, 50)

    // 自动移除
    setTimeout(() => {
      notification.style.opacity = '0'
      notification.style.transform = 'translateX(100%)'
      setTimeout(() => notification.remove(), 300)
    }, 3000)
  }

  // 固定的检查间隔时间(毫秒)
  const CHECK_INTERVAL = 1000
  // 重试延迟时间(毫秒)
  let retryDelay = 1000
  // 重试计数器
  let retryCount = 0
  // 重试次数阈值,达到该阈值后增加重试延迟
  const threshold = 5
  // 每次增加的重试延迟时间(毫秒),正常情况增加2秒
  const normalDelayIncrement = 2000
  // 当检测到频率过快提示时每次增加的重试延迟时间(毫秒),即30秒
  const fastFrequencyDelayIncrement = 30000
  // 上次重试的时间戳
  let lastRetryTime = 0

  const checkAndRetry = () => {
    // 检查是否没有 .ds-loading 元素
    const loadingElements = document.querySelectorAll('.ds-loading')
    const hasLoading = loadingElements.length > 0

    // 检查页面是否存在繁忙提示
    const contentList = document.querySelectorAll('.ds-markdown')
    let hasBusyMessage = false
    const busyMessages = [
      '<p>服务器繁忙,请稍后再试。</p>',
      '<p>The server is busy. Please try again later.</p>',
    ]

    for (let i = 0; i < contentList.length; i++) {
      if (busyMessages.includes(contentList[i].innerHTML)) {
        hasBusyMessage = true
        break
      }
    }

    // 如果没有 .ds-loading 元素且没有繁忙提示,重置重试计数
    if (!hasLoading && !hasBusyMessage) {
      if (retryCount > 0) {
        createNotification('已重置重试次数和重试延迟', 'success')
      }
      retryCount = 0
      retryDelay = 1000
      lastRetryTime = 0
    }

    const lastContent =
      contentList.length > 0
        ? contentList[contentList.length - 1].innerHTML
        : ''
    if (busyMessages.includes(lastContent)) {
      const currentTime = Date.now()
      // 检查是否已经过了足够的重试延迟时间
      if (currentTime - lastRetryTime >= retryDelay) {
        const retryBtn = Array.from(
          document.querySelectorAll('.ds-icon-button')
        )
          .reverse()
          .find((btn) => {
            const svg = btn.querySelector('svg')
            return svg && svg.querySelector('#重新生成')
          })

        if (retryBtn) {
          retryBtn.click()
          lastRetryTime = currentTime
          retryCount++
          createNotification(`已点击重试,重试次数: ${retryCount}`, 'success')

          let increment = normalDelayIncrement
          // 检查是否有频率过快的提示
          const toastContents = document.querySelectorAll('.ds-toast__content')
          for (let i = 0; i < toastContents.length; i++) {
            if (
              toastContents[i].textContent ===
              '你发送消息的频率过快,请稍后再发'
            ) {
              increment = fastFrequencyDelayIncrement
              break
            }
          }

          // 当重试次数达到阈值时,增加重试延迟时间
          if (retryCount >= threshold) {
            retryDelay += increment
            createNotification(
              `重试次数过多,重试延迟已调整为 ${retryDelay/1000} 秒`,
              'warning'
            )
          }
        }
      }
    }
  }

  // 以固定间隔运行检查
  setInterval(checkAndRetry, CHECK_INTERVAL)
})()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址