🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

DeepSeek Auto-Retry

Automatically click the retry button when DS message blocks show "The server is busy. Please try again later." or "Thought for 0 seconds". Uses a cooldown so that repeated clicks occur if the error persists.Automatically click the retry button when DS message blocks show error messages.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         DeepSeek Auto-Retry
// @version      1.1
// @description  Automatically click the retry button when DS message blocks show "The server is busy. Please try again later." or "Thought for 0 seconds". Uses a cooldown so that repeated clicks occur if the error persists.Automatically click the retry button when DS message blocks show error messages.
// @author       Staninna
// @match        https://chat.deepseek.com/*
// @grant        none
// @license      MIT
// @namespace    http://tampermonkey.net/
// ==/UserScript==

(function () {
  "use strict";

  // Configuration object with error phrases and timing settings.
  const config = {
    autoRetryEnabled: true,
    cooldown: 15000, // 15 seconds between retries per message block.
    interval: 3000, // Check every 3 seconds.
    errorMessages: [
      "The server is busy. Please try again later.",
      "服务器繁忙,请稍后再试。",
      "Thought for 0 seconds",
    ],
  };

  // Returns true if the provided text contains any of the error phrases.
  function isError(text) {
    return config.errorMessages.some((msg) => text.includes(msg));
  }

  // Locate the retry button by looking for a matching SVG element.
  function findRetryButton() {
    const buttons = document.querySelectorAll("div.ds-icon-button");

    // Loop backward to prioritize the end of the array.
    for (let i = buttons.length - 1; i >= 0; i--) {
      const btn = buttons[i];
      if (btn.querySelector("svg rect#重新生成") !== null) {
        return btn;
      }
    }
    return null;
  }

  // Returns the inner text of a DS markdown block.
  function getMarkdownText(el) {
    return el.innerText || "";
  }

  // Checks all DS markdown blocks for error messages. If a block shows an error and
  // if the cooldown period has passed, this function triggers a retry click.
  function checkErrorMarkdowns() {
    if (!config.autoRetryEnabled) return;

    const blocks = document.querySelectorAll(
      "div.ds-markdown.ds-markdown--block"
    );
    blocks.forEach((block) => {
      const text = getMarkdownText(block);
      if (isError(text)) {
        const last = parseInt(block.dataset.lastRetry || "0", 10);
        const now = Date.now();
        if (now - last > config.cooldown) {
          block.dataset.lastRetry = now.toString();
          console.log("Auto-retry triggered due to error text in markdown block.");
          const btn = findRetryButton();
          if (btn) {
            btn.click();
          } else {
            console.log("Retry button not found.");
          }
        }
      }
    });
  }

  // Creates a DS-style UI toggle to allow users to enable/disable the auto-retry.
  function createToggleUI() {
    const uiContainer = document.createElement("div");
    uiContainer.id = "autoRetryToggleUI";
    uiContainer.className = "ds-form-item ds-form-item--label-s";
    uiContainer.style.position = "fixed";
    uiContainer.style.bottom = "70px";
    uiContainer.style.right = "20px";
    uiContainer.style.zIndex = "9999";

    uiContainer.innerHTML = `
      <label class="ds-checkbox-wrapper ds-checkbox-wrapper--m" 
             style="cursor: pointer; user-select: none;">
        <span class="ds-checkbox">
          <input type="checkbox" id="autoRetryCheckbox" class="ds-checkbox__input" checked>
          <span class="ds-checkbox__box"></span>
        </span>
        <span class="ds-checkbox__label">Auto‑Retry</span>
      </label>
    `;
    document.body.appendChild(uiContainer);

    document
      .getElementById("autoRetryCheckbox")
      .addEventListener("change", function () {
        config.autoRetryEnabled = this.checked;
        console.log("Auto‑Retry turned " + (this.checked ? "ON" : "OFF"));
      });
  }

  // Initialize the script: Set up the UI and start periodic error checks.
  function initialize() {
    createToggleUI();
    setInterval(checkErrorMarkdowns, config.interval);
  }

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", initialize);
  } else {
    initialize();
  }
})();