Last active
May 6, 2025 13:55
-
-
Save 6uclz1/d8eb8a6dede3d371bddf54b744ea8f2f to your computer and use it in GitHub Desktop.
tampermonkey scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Ctrl+Enter Sender | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.1 | |
| // @description Send messages with Ctrl+Enter instead of just Enter. | |
| // @author You | |
| // @match https://*/* | |
| // @grant none | |
| // @license MIT | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const SITE_CONFIGS = [ | |
| { | |
| match: /https:\/\/gemini\.google\.com\//, | |
| textareaSelector: 'div.ql-editor[contenteditable="true"]', | |
| sendButtonSelector: null | |
| }, | |
| { | |
| match: /https:\/\/notebooklm\.google\.com\//, | |
| textareaSelector: 'textarea.query-box-input', | |
| sendButtonSelector: 'button.submit-button' | |
| }, | |
| { | |
| match: /https:\/\/chatgpt\.com\//, | |
| textareaSelector: 'div[id="prompt-textarea"]', | |
| sendButtonSelector: 'button[id="composer-submit-button"]' | |
| }, | |
| ]; | |
| function getSiteConfig() { | |
| return SITE_CONFIGS.find(cfg => cfg.match.test(location.href)); | |
| } | |
| const config = getSiteConfig(); | |
| if (!config) { | |
| return; | |
| } | |
| document.addEventListener('keydown', function (event) { | |
| const textarea = event.target.matches(config.textareaSelector); | |
| if (textarea && event.key === 'Enter' && event.shiftKey) { | |
| const start = targetElement.selectionStart; | |
| const end = targetElement.selectionEnd; | |
| const value = targetElement.value; | |
| targetElement.value = value.substring(0, start) + '\n' + value.substring(end); | |
| targetElement.selectionStart = targetElement.selectionEnd = start + 1; | |
| const inputEvent = new Event('input', { bubbles: true, cancelable: true }); | |
| targetElement.dispatchEvent(inputEvent); | |
| } | |
| if (textarea && event.key === 'Enter' && !event.ctrlKey && !event.metaKey) { | |
| event.preventDefault(); | |
| event.stopImmediatePropagation(); | |
| } | |
| if (textarea && event.key === 'Enter' && (event.ctrlKey || event.metaKey)) { | |
| if (config.sendButtonSelector) { | |
| const sendButton = document.querySelector(config.sendButtonSelector); | |
| if (sendButton && !sendButton.disabled) { | |
| sendButton.click(); | |
| event.preventDefault(); | |
| } | |
| } | |
| } | |
| }, true); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment