copy-chatgpt-input

chatgpt发送前自动复制输入框内容到剪切板

  1. // ==UserScript==
  2. // @name copy-chatgpt-input
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-02-20
  5. // @description chatgpt发送前自动复制输入框内容到剪切板
  6. // @author SeekingLight233
  7. // @match https://chat.openai.com
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. main()
  17.  
  18. let copyTmp = "";
  19.  
  20. function main() {
  21. console.log("init copy-input");
  22. const sendBtn = getSendBtn();
  23. const textAreaNode = getTextAreaNode();
  24.  
  25. textAreaNode.addEventListener("input", (e) => {
  26. const val = e.target.value;
  27. copyTmp = val;
  28. })
  29.  
  30. document.body.addEventListener("click", (event) => {
  31. const sendBtn = event.target.closest('[data-testid="send-button"]');
  32. if (sendBtn) {
  33. copyValue(copyTmp);
  34. }
  35. });
  36.  
  37. document.addEventListener("keydown", function (event) {
  38. if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
  39. copyValue(copyTmp)
  40. }
  41. })
  42. }
  43.  
  44. function copyValue(value) {
  45. navigator.clipboard.writeText(value).then(() => {
  46. // console.log('copy input:', value);
  47. }).catch(err => {
  48. // console.error('copy failed', err);
  49. });
  50. }
  51.  
  52. function getTextAreaNode() {
  53. return document.getElementsByTagName("textarea")?.[0];
  54. }
  55.  
  56. function getTextAreaValue() {
  57. const node = getTextAreaNode();
  58. return node?.value ?? ""
  59. }
  60.  
  61. function getSendBtn() {
  62. const textAreaNode = getTextAreaNode();
  63. const pNode = textAreaNode.parentElement;
  64. const sendBtn = pNode.querySelector('[data-testid="send-button"]');
  65. return sendBtn;
  66. }
  67.  
  68. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址