DeepSeek Chat Ctrl+Enter to Send

Ctrl+Enter or Cmd+Enter sends the message, Enter only breaks the line(applies to chat.deepseek.com)

// ==UserScript==
// @name         DeepSeek Chat Ctrl+Enter to Send
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Ctrl+Enter or Cmd+Enter sends the message, Enter only breaks the line(applies to chat.deepseek.com)
// @author       ChatGPT
// @match        https://chat.deepseek.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    document.addEventListener('keydown', function (e) {
        if (document.activeElement?.tagName === 'TEXTAREA') {
            if (e.key === 'Enter') {
                e.preventDefault();
                e.stopImmediatePropagation();

                if (e.ctrlKey || e.metaKey) {
                    // Ctrl+Enter or Cmd+Enter → send
                    const sendBtn = document.querySelector('path[d="M8.3125 0.981648C8.66767 1.05456 8.97902 1.20565 9.2627 1.4338C9.48724 1.61444 9.73029 1.85939 9.97949 2.1086L14.707 6.83614L13.293 8.2502L9 3.95723V15.0432H7V3.95723L2.70703 8.2502L1.29297 6.83614L6.02051 2.1086C6.26971 1.85939 6.51277 1.61444 6.7373 1.4338C6.97662 1.24132 7.28445 1.04548 7.6875 0.981648C7.8973 0.948471 8.1031 0.956625 8.3125 0.981648Z"]')?.closest('div[role="button"]');
                    if (!sendBtn) {
                        console.warn('[Tampermonkey] ❌ Send button not found');
                        return;
                    }
                    sendBtn.click();
                } else {
                    // Only Enter → inserts a newline (prevents default sending)
                    const textarea = document.activeElement;
                    const start = textarea.selectionStart;
                    const end = textarea.selectionEnd;
                    const value = textarea.value;

                    // Insert a line break
                    textarea.value = value.slice(0, start) + '\n' + value.slice(end);
                    textarea.selectionStart = textarea.selectionEnd = start + 1;

                    // Trigger input event to update state
                    textarea.dispatchEvent(new Event('input', { bubbles: true }));
                }
            }
        }
    }, true);
})();