DeepSeek Chat Ctrl+Enter to Send

Ctrl+Enter 或 Cmd+Enter 发送消息,Enter 仅换行(适用于 chat.deepseek.com)

// ==UserScript==
// @name         DeepSeek Chat Ctrl+Enter to Send
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Ctrl+Enter 或 Cmd+Enter 发送消息,Enter 仅换行(适用于 chat.deepseek.com)
// @author       ChatGPT
// @match        https://chat.deepseek.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    document.addEventListener('keydown', function (e) {
        const activeElement = document.activeElement;

        if (activeElement && activeElement.tagName === 'TEXTAREA') {
            if (e.key === 'Enter') {
                if (e.ctrlKey || e.metaKey) {
                    // Ctrl+Enter 或 Cmd+Enter → 发送
                    e.preventDefault();
                    e.stopImmediatePropagation();

                    const sendBtn = document.querySelector('div[role="button"][aria-disabled="false"]');
                    if (sendBtn) {
                        sendBtn.click();
                    } else {
                        console.warn('[Tampermonkey] ❌ 未找到发送按钮');
                    }
                } else {
                    // 仅 Enter → 插入换行(阻止默认发送)
                    e.preventDefault();
                    e.stopImmediatePropagation();

                    const textarea = activeElement;
                    const start = textarea.selectionStart;
                    const end = textarea.selectionEnd;
                    const value = textarea.value;

                    // 插入换行符
                    textarea.value = value.slice(0, start) + '\n' + value.slice(end);
                    textarea.selectionStart = textarea.selectionEnd = start + 1;

                    // 触发 input 事件更新状态
                    textarea.dispatchEvent(new Event('input', { bubbles: true }));
                }
            }
        }
    }, true);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址