DeepSeek Chat Ctrl+Enter to Send

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();