// ==UserScript== // @name Auto-Retry (DS Style) // @namespace http://tampermonkey.net/ // @version 0.5 // @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. // @author Staninna // @match https://chat.deepseek.com/* // @grant none // ==/UserScript== (function () { "use strict"; // Toggle for whether auto-retry is enabled. let autoRetryEnabled = true; // Error trigger phrases: const errorPhrase = "The server is busy. Please try again later."; const altTrigger = "Thought for 0 seconds"; // Return true if the provided text qualifies as an error message. function isError(text) { return text.includes(errorPhrase) || text.includes(altTrigger); } // Helper: Find the retry button. We assume DS’s retry/regenerate button contains an SVG whose id is "重新生成". function findRetryButton() { const buttons = Array.from(document.querySelectorAll("div.ds-icon-button")); return buttons.find((btn) => btn.querySelector("svg rect#重新生成") !== null); } // Helper: Get the text from a DS markdown block. function getMarkdownText(el) { return el.innerText || ""; } // Main function: for each DS markdown block that may contain an error, trigger a retry click. // We use a 15-second cooldown (adjustable) per element. function checkErrorMarkdowns() { if (!autoRetryEnabled) return; const cooldown = 15000; // 15 seconds // DS error text appears in DS markdown blocks – adjust the selector if needed. // For example:
...
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 > 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."); } } } }); } // Create a DS-style toggle UI so the user can enable/disable auto-retry. function createToggleUI() { const uiContainer = document.createElement("div"); uiContainer.id = "autoRetryToggleUI"; // Apply DS form item classes for consistency. 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 = ` `; document.body.appendChild(uiContainer); document.getElementById("autoRetryCheckbox").addEventListener("change", function () { autoRetryEnabled = this.checked; console.log("Auto‑Retry turned " + (autoRetryEnabled ? "ON" : "OFF")); }); } // Initialize the toggle UI and start the periodic check (every 3 seconds). createToggleUI(); setInterval(checkErrorMarkdowns, 3000); })();