Greasy Fork

Greasy Fork is available in English.

DeepSeek自动重试

检测到"服务器繁忙"时自动点击重试按钮

当前为 2025-02-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         DeepSeek自动重试
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  检测到"服务器繁忙"时自动点击重试按钮
// @author       dy
// @match        https://chat.deepseek.com/*
// @grant        none
// @license      none
// ==/UserScript==
(function() {
    'use strict';

    const BUSY_MSG = '服务器繁忙,请稍后再试';
    const LIMIT_MSG = '你发送消息的频率过快,请稍后再发';
    const CHECK_TIME = 1000;
    let tryCount = 0;
    let showTip = false;

    // 创建可关闭的提示框
    function showMsg(msg, forever = false) {
        if (showTip) return null;
        showTip = true;

        const tip = document.createElement('div');
        tip.style.cssText = `
            position: fixed;
            top: 20px;
            right: 20px;
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
            z-index: 9999;
            transition: opacity 0.3s;
            display: flex;
            align-items: center;
            gap: 10px;
        `;

        const text = document.createElement('div');
        text.textContent = msg;
        tip.appendChild(text);

        const closeBtn = document.createElement('button');
        closeBtn.innerHTML = '✕';
        closeBtn.style.cssText = `
            background: none;
            border: none;
            color: white;
            cursor: pointer;
            font-size: 16px;
            padding: 0 5px;
        `;
        closeBtn.onclick = () => {
            tip.style.opacity = '0';
            setTimeout(() => {
                tip.remove();
                showTip = false;
                tryCount = 0;
            }, 300);
        };
        tip.appendChild(closeBtn);

        document.body.appendChild(tip);
        return tip;
    }

    // 创建临时提示
    function showTempMsg(msg) {
        if (showTip) return null;
        const tip = showMsg(msg);
        if (tip) {
            setTimeout(() => {
                tip.style.opacity = '0';
                setTimeout(() => {
                    tip.remove();
                    showTip = false;
                }, 300);
            }, 3000);
        }
        return tip;
    }

    // 查找重试按钮
    function findBtn(err) {
        let parent = err;
        while (parent && !parent.querySelector('.ds-icon-button')) {
            parent = parent.parentElement;
        }
        if (!parent) return null;

        const btns = Array.from(parent.querySelectorAll('.ds-icon-button'));
        return btns.find(btn => {
            const svg = btn.querySelector('svg');
            return svg && svg.querySelector('#重新生成');
        });
    }

    // 自动重试主函数
    function autoRetry() {
        const limitTip = Array.from(document.querySelectorAll('.ds-toast__content')).find(el => 
            el.textContent && el.textContent.trim() === LIMIT_MSG
        );

        if (limitTip) {
            showMsg('检测到频率过快,稍等一会吧', true);
            return;
        }

        const errList = Array.from(document.querySelectorAll('.ds-markdown--block')).filter(el => {
            const text = el.textContent?.trim() || '';
            if (text !== BUSY_MSG) {
                return false;
            }
            
            let parent = el;
            while (parent) {
                if (parent.classList.contains('fa81')) {
                    return false;
                }
                parent = parent.parentElement;
            }
            return true;
        });

        if (errList.length > 0) {
            const retryBtn = findBtn(errList[0]);
            
            if (retryBtn) {
                tryCount++;
                
                if (tryCount > 10) {
                    showMsg('检测到多次失败,DeepSeek可能当前算力不足', true);
                    return;
                }

                const tip = showTempMsg('检测到服务器繁忙,即将自动重试...');
                if (!tip) return;

                const wait = 1500 + Math.random() * 1500;
                setTimeout(() => {
                    console.log('找到重试按钮,自动点击');
                    retryBtn.dispatchEvent(new MouseEvent('click', {
                        view: window,
                        bubbles: true,
                        cancelable: true
                    }));
                }, wait);
            }
        }
    }

    // 定期检查
    setInterval(autoRetry, CHECK_TIME);
})();