Auto retry when server busy detected by text or SVG icon, with toggle UI and cooldown.
当前为
// ==UserScript==
// @name DeepSeek Auto-Retry with Text & SVG Detection
// @version 1.3
// @description Auto retry when server busy detected by text or SVG icon, with toggle UI and cooldown.
// @author Blakken
// @match https://chat.deepseek.com/*
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/1477546
// ==/UserScript==
(function () {
"use strict";
const config = {
autoRetryEnabled: true,
cooldown: 15000, // 15 seconds cooldown per message block
interval: 3000, // Check every 3 seconds
errorMessages: [
"The server is busy. Please try again later.",
"服务器繁忙,请稍后再试。",
"Thought for 0 seconds",
"Server busy, please try again later."
],
};
let retryCount = 0;
// Create and insert retry counter display in bottom right corner
function createRetryCounter() {
let counterDiv = document.createElement("div");
counterDiv.id = "autoRetryCounter";
counterDiv.style.position = "fixed";
counterDiv.style.bottom = "10px";
counterDiv.style.right = "10px";
counterDiv.style.padding = "6px 12px";
counterDiv.style.backgroundColor = "rgba(245, 158, 11, 0.85)"; // same amber color as SVG fill #F59E0B
counterDiv.style.color = "#fff";
counterDiv.style.fontWeight = "bold";
counterDiv.style.fontFamily = "Arial, sans-serif";
counterDiv.style.fontSize = "14px";
counterDiv.style.borderRadius = "5px";
counterDiv.style.zIndex = "9999";
counterDiv.textContent = "Auto-Retry count: 0";
document.body.appendChild(counterDiv);
}
// Update retry counter text
function updateRetryCounter() {
const counterDiv = document.getElementById("autoRetryCounter");
if (counterDiv) {
counterDiv.textContent = `Auto-Retry count: ${retryCount}`;
}
}
// Check if text contains any error message
function isError(text) {
return config.errorMessages.some((msg) => text.includes(msg));
}
// Find the retry button by SVG path detection or class names etc.
function findRetryButton() {
// Example: retry buttons may have a class like 'retry-btn' or contain specific SVGs
// Adjust selector to match the actual retry button on the site
const buttons = document.querySelectorAll("button, div.ds-icon-button, div.ac2694a7");
for (let btn of buttons) {
// You can customize this detection, here is a simple example by text content or SVG detection
if (btn.innerText && btn.innerText.toLowerCase().includes("retry")) {
return btn;
}
if (btn.querySelector("svg")) {
// Optionally detect the specific svg path or fill color here
// For demo, we assume any button with SVG is the retry
return btn;
}
}
return null;
}
// Main check function for errors and triggering retry
function checkErrorBlocks() {
if (!config.autoRetryEnabled) return;
const blocks = document.querySelectorAll("div.ac2694a7, div.ds-markdown.ds-markdown--block, span");
blocks.forEach((block) => {
const text = block.innerText || "";
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.");
const btn = findRetryButton();
if (btn) {
btn.click();
retryCount++;
updateRetryCounter();
} else {
console.log("Retry button not found.");
}
}
}
});
}
function initialize() {
createRetryCounter();
setInterval(checkErrorBlocks, config.interval);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initialize);
} else {
initialize();
}
})();