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

Greasy fork 爱吃馍镜像

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.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

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

公众号二维码

扫码关注【爱吃馍】

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

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

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

公众号二维码

扫码关注【爱吃馍】

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

// ==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();
  }
})();