Greasy Fork is available in English.

GPT窄屏回车恢复发送内容

修复 ChatGPT 窄屏下因历史记录疑似被检测为移动端导致回车变成换行的问题

Tính đến 07-11-2024. Xem phiên bản mới nhất.

  1. // ==UserScript==
  2. // @name GPT窄屏回车恢复发送内容
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description 修复 ChatGPT 窄屏下因历史记录疑似被检测为移动端导致回车变成换行的问题
  6. // @author wzj042
  7. // @match https://chatgpt.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=chatgpt.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. const textareaSelector = '.text-token-text-primary div[contenteditable]';
  16. const buttonSelector = "button[data-testid='send-button']";
  17.  
  18. // 为 document 添加全局的 keydown 事件监听器
  19. document.addEventListener("keydown", function(event) {
  20. // 检查是否按下了 Enter 键,且没有按下Shift 键
  21. if (event.key === "Enter" && !event.shiftKey ) {
  22. // 获取 textarea 和按钮元素
  23. const textarea = document.querySelector(textareaSelector);
  24. const button = document.querySelector(buttonSelector);
  25.  
  26. // 检查 textarea 和按钮是否存在,并且 textarea 中是否有内容
  27. if (textarea && button && textarea.innerText.trim() !== "") {
  28. event.preventDefault(); // 阻止默认的 Enter 行为,如换行
  29. button.click(); // 点击按钮
  30. console.log("已点击发送按钮");
  31. }
  32. }
  33. });
  34. })();