DeepSeek Chat Ctrl+Enter to Send

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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