ChatGPT自动接上文继续

让ChatGPT在中断回答的时候自动输入「请接上文继续」并发送

  1. // ==UserScript==
  2. // @name ChatGPT自动接上文继续
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description 让ChatGPT在中断回答的时候自动输入「请接上文继续」并发送
  6. // @author yedsn
  7. // @match http*://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. let autoSendFlag = false;
  17. let checkboxContainer = null;
  18.  
  19. // 创建checkbox
  20. (function generateCheckbox() {
  21.  
  22. // 创建checkbox
  23. checkboxContainer = document.createElement('button');
  24. checkboxContainer.classList.add('btn', 'btn-autosend', 'relative', 'border-0', 'md:border');
  25. checkboxContainer.style.fontSize = '.875rem';
  26. checkboxContainer.style.lineHeight = '1.25rem';
  27. const checkboxLabel = document.createElement('label');
  28. const checkbox = document.createElement('input');
  29. checkbox.style.marginRight = ".5rem";
  30. checkbox.type = 'checkbox';
  31. checkbox.id = 'auto-operate-checkbox';
  32. checkboxLabel.appendChild(checkbox);
  33. const label = document.createTextNode('中断后自动发送“请接上文继续”');
  34. checkboxLabel.appendChild(label);
  35. checkboxContainer.appendChild(checkboxLabel);
  36.  
  37. checkbox.addEventListener('change', function() {
  38. autoSendFlag = this.checked;
  39. });
  40.  
  41. // 添加样式
  42. const checkboxStyle = `
  43. <style>
  44. .dark .btn-autosend {
  45. --tw-border-opacity: 1;
  46. --tw-bg-opacity: 1;
  47. --tw-text-opacity: 1;
  48. background-color: rgba(52,53,65,var(--tw-bg-opacity));
  49. border-color: rgba(86,88,105,var(--tw-border-opacity));
  50. color: rgba(217,217,227,var(--tw-text-opacity));
  51. }
  52. .light .btn-autosend {
  53. background-color: rgba(255,255,255,1);
  54. border-color: rgba(0,0,0,.1);
  55. color: rgba(64,65,79,1);
  56. }
  57. </style>
  58. `;
  59. document.body.insertAdjacentHTML('beforeend', checkboxStyle);
  60.  
  61.  
  62.  
  63. })();
  64.  
  65. // 创建一个 MutationObserver 实例,监听 body 元素内子元素的变化
  66. const observer = new MutationObserver(function(mutations) {
  67.  
  68. // document.body.appendChild(checkboxContainer);
  69. if(!document.getElementById("auto-operate-checkbox")) {
  70. const btnNeutral = document.querySelector('.btn-neutral');
  71. if(btnNeutral) {
  72. btnNeutral.parentNode.insertBefore(checkboxContainer, btnNeutral);
  73. }
  74. }
  75.  
  76.  
  77. if(autoSendFlag) {
  78. // 执行自动发送
  79. const button = document.querySelector('.btn-neutral');
  80. if (!button || button.querySelector('div').textContent.trim() != "Stop generating") {
  81. // debugger
  82.  
  83. // 找到页面中最后一个不为 __next-route-announcer__ 的 p 元素
  84. const paragraphs = Array.from(document.getElementsByTagName('p'));
  85. const lastParagraph = paragraphs.filter(p => p.id !== '__next-route-announcer__').pop();
  86.  
  87. // 检查最后一个 p 元素内容是否以中文句号结尾
  88. if (lastParagraph && !lastParagraph.parentNode.classList.contains('result-streaming') && !/\。$/.test(lastParagraph.textContent.trim())) {
  89. setTimeout(function () {
  90. // 找到 textarea 元素,并填充内容为 "请接上文继续"
  91. const textarea = document.querySelector('textarea');
  92. textarea.value = '请接上文继续';
  93.  
  94. // 触发 input 事件
  95. const event = new Event('input', { bubbles: true });
  96. textarea.dispatchEvent(event);
  97.  
  98. // 找到与 textarea 同级的 button 元素,并点击它
  99. const siblingButton = textarea.nextElementSibling;
  100. siblingButton.click();
  101. }, Math.floor(Math.random() * (3000 - 500 + 1) + 500));
  102. }
  103.  
  104.  
  105. }
  106. }
  107. });
  108.  
  109. const observerConfig = { childList: true, subtree: true };
  110. observer.observe(document.body, observerConfig);
  111.  
  112. })();

QingJ © 2025

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