ChatGPT 自动继续 🔄

⚡ 自动点击ChatGPT中的“继续生成”按钮,处理错误!

  1. // ==UserScript==
  2. // @name ChatGPT Auto-Continue 🔄
  3. // @description ⚡ Automatically click the 'Continue Generating' button in ChatGPT, handling errors!
  4. // @author mefengl
  5. // @version 1.1.18
  6. // @namespace https://github.com/mefengl
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  8. // @license MIT
  9. // @match https://chatgpt.com/*
  10. // @grant none
  11.  
  12. // @name:en ChatGPT Auto-Continue 🔄
  13. // @description:en ⚡ Automatically click the 'Continue Generating' button in ChatGPT, handling errors!
  14. // @name:zh-CN ChatGPT 自动继续 🔄
  15. // @description:zh-CN ⚡ 自动点击ChatGPT中的“继续生成”按钮,处理错误!
  16. // @name:es ChatGPT Auto-Continuar 🔄
  17. // @description:es ⚡ ¡Haz clic automáticamente en el botón 'Continuar generando' en ChatGPT, manejando errores!
  18. // @name:hi ChatGPT स्वचालित जारी रखें 🔄
  19. // @description:hi ⚡ ChatGPT में 'जारी रखने' बटन पर स्वचालित रूप से क्लिक करें, त्रुटियों को संभालते हुए!
  20. // @name:ar ChatGPT التكميل الآلي 🔄
  21. // @description:ar ⚡ انقر تلقائيًا على زر 'متابعة التوليد' في ChatGPT ، معالجة الأخطاء!
  22. // @name:pt ChatGPT Auto-Continuar 🔄
  23. // @description:pt ⚡ Clique automaticamente no botão 'Continuar Gerando' no ChatGPT, tratando erros!
  24. // @name:ru ChatGPT Авто-Продолжение 🔄
  25. // @description:ru ⚡ Автоматически нажимайте на кнопку "Продолжить генерацию" в ChatGPT, обрабатывая ошибки!
  26. // @name:ja ChatGPT 自動続行 🔄
  27. // @description:ja ⚡ ChatGPTの「続けて生成」ボタンを自動的にクリックし、エラーを処理します!
  28. // @name:de ChatGPT Auto-Fortsetzen 🔄
  29. // @description:de ⚡ Klicken Sie automatisch auf die Schaltfläche "Generierung fortsetzen" in ChatGPT, Fehler behandeln!
  30. // @name:fr ChatGPT Auto-Continuer 🔄
  31. // @description:fr ⚡ Cliquez automatiquement sur le bouton 'Continuer à générer' dans ChatGPT, gérer les erreurs!
  32. // ==/UserScript==
  33. "use strict";
  34. (() => {
  35. var __create = Object.create;
  36. var __defProp = Object.defineProperty;
  37. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  38. var __getOwnPropNames = Object.getOwnPropertyNames;
  39. var __getProtoOf = Object.getPrototypeOf;
  40. var __hasOwnProp = Object.prototype.hasOwnProperty;
  41. var __commonJS = (cb, mod) => function __require() {
  42. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  43. };
  44. var __copyProps = (to, from, except, desc) => {
  45. if (from && typeof from === "object" || typeof from === "function") {
  46. for (let key of __getOwnPropNames(from))
  47. if (!__hasOwnProp.call(to, key) && key !== except)
  48. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  49. }
  50. return to;
  51. };
  52. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  53. // If the importer is in node compatibility mode or this is not an ESM
  54. // file that has been converted to a CommonJS file using a Babel-
  55. // compatible transform (i.e. "__esModule" has not been set), then set
  56. // "default" to the CommonJS "module.exports" for node compatibility.
  57. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  58. mod
  59. ));
  60. var __async = (__this, __arguments, generator) => {
  61. return new Promise((resolve, reject) => {
  62. var fulfilled = (value) => {
  63. try {
  64. step(generator.next(value));
  65. } catch (e) {
  66. reject(e);
  67. }
  68. };
  69. var rejected = (value) => {
  70. try {
  71. step(generator.throw(value));
  72. } catch (e) {
  73. reject(e);
  74. }
  75. };
  76. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  77. step((generator = generator.apply(__this, __arguments)).next());
  78. });
  79. };
  80.  
  81. // ../../packages/chatkit/dist/chatgpt/index.js
  82. var require_chatgpt = __commonJS({
  83. "../../packages/chatkit/dist/chatgpt/index.js"(exports, module) {
  84. "use strict";
  85. var __defProp2 = Object.defineProperty;
  86. var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
  87. var __getOwnPropNames2 = Object.getOwnPropertyNames;
  88. var __hasOwnProp2 = Object.prototype.hasOwnProperty;
  89. var __export = (target, all) => {
  90. for (var name in all)
  91. __defProp2(target, name, { get: all[name], enumerable: true });
  92. };
  93. var __copyProps2 = (to, from, except, desc) => {
  94. if (from && typeof from === "object" || typeof from === "function") {
  95. for (let key of __getOwnPropNames2(from))
  96. if (!__hasOwnProp2.call(to, key) && key !== except)
  97. __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
  98. }
  99. return to;
  100. };
  101. var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
  102. var chatgpt_exports = {};
  103. __export(chatgpt_exports, {
  104. clickFollowUpButton: () => clickFollowUpButton,
  105. getButton: () => getButton,
  106. getContinueGeneratingButton: () => getContinueGeneratingButton2,
  107. getConversation: () => getConversation,
  108. getCopyLinkButton: () => getCopyLinkButton,
  109. getFollowUpButtons: () => getFollowUpButtons,
  110. getHistoryBlockTitle: () => getHistoryBlockTitle,
  111. getHistoryBlocks: () => getHistoryBlocks,
  112. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  113. getInitialButtons: () => getInitialButtons,
  114. getLastResponse: () => getLastResponse,
  115. getLastResponseElement: () => getLastResponseElement,
  116. getModelSelectButton: () => getModelSelectButton,
  117. getNav: () => getNav,
  118. getNewModelSelectButtons: () => getNewModelSelectButtons,
  119. getRegenerateButton: () => getRegenerateButton2,
  120. getResponseElementHTMLs: () => getResponseElementHTMLs,
  121. getShareChatButton: () => getShareChatButton,
  122. getStopGeneratingButton: () => getStopGeneratingButton,
  123. getSubmitButton: () => getSubmitButton,
  124. getTextarea: () => getTextarea2,
  125. getTextareaValue: () => getTextareaValue,
  126. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  127. isConversationStarted: () => isConversationStarted,
  128. isGenerating: () => isGenerating2,
  129. isHorizontalConversation: () => isHorizontalConversation,
  130. onSend: () => onSend,
  131. regenerate: () => regenerate,
  132. send: () => send,
  133. sendArray: () => sendArray,
  134. setHorizontalConversation: () => setHorizontalConversation,
  135. setPromptListener: () => setPromptListener,
  136. setPureConversation: () => setPureConversation,
  137. setTextarea: () => setTextarea,
  138. waitForIdle: () => waitForIdle
  139. });
  140. module.exports = __toCommonJS(chatgpt_exports);
  141. function getNav() {
  142. return document.querySelector("nav");
  143. }
  144. function getHistoryBlocks() {
  145. const nav = getNav();
  146. if (!nav)
  147. return [];
  148. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  149. return result;
  150. }
  151. function getHistoryBlockTitle(historyBlock) {
  152. var _a;
  153. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  154. }
  155. function getHistoryBlocksWithTitle() {
  156. const historyBlocks = getHistoryBlocks();
  157. const result = historyBlocks.map((historyBlock) => ({
  158. block: historyBlock,
  159. title: getHistoryBlockTitle(historyBlock)
  160. }));
  161. return result;
  162. }
  163. function getTextarea2() {
  164. const form = document.querySelector("form");
  165. if (!form)
  166. return;
  167. const textareas = form.querySelectorAll("textarea");
  168. const result = textareas[0];
  169. return result;
  170. }
  171. function getNewSubmitButton() {
  172. return document.querySelector('button[data-testid$="send-button"]');
  173. }
  174. function getSubmitButton() {
  175. if (getNewSubmitButton()) {
  176. return getNewSubmitButton();
  177. }
  178. const textarea = getTextarea2();
  179. if (!textarea)
  180. return;
  181. return textarea.nextElementSibling;
  182. }
  183. function getInitialButtons() {
  184. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => button.querySelectorAll(".truncate").length === 2);
  185. }
  186. function getFollowUpButtons() {
  187. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  188. var _a;
  189. return (_a = button.textContent) == null ? void 0 : _a.trim().match(/[.!?]$/);
  190. });
  191. }
  192. function clickFollowUpButton(index) {
  193. const followUpButtons = getFollowUpButtons();
  194. if (followUpButtons.length === 0)
  195. return;
  196. if (index === void 0 || index < 0 || index >= followUpButtons.length) {
  197. index = Math.floor(Math.random() * followUpButtons.length);
  198. }
  199. followUpButtons[index].click();
  200. }
  201. function getButton(text) {
  202. const button = Array.from(document.querySelectorAll('button[data-testid$="button"]')).find((button2) => {
  203. var _a;
  204. return (_a = button2.getAttribute("data-testid")) == null ? void 0 : _a.includes(text);
  205. });
  206. if (button)
  207. return button;
  208. return Array.from(document.querySelectorAll('button[as="button"]')).find((button2) => {
  209. var _a;
  210. return (_a = button2.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  211. });
  212. }
  213. function getRegenerateButton2() {
  214. return getButton("regenerate");
  215. }
  216. function getContinueGeneratingButton2() {
  217. const buttonInWideScreen = getButton("continue");
  218. if (buttonInWideScreen)
  219. return buttonInWideScreen;
  220. function getNthGenerationDescendants(element, generation) {
  221. const descendants = [];
  222. function findDescendants(node, currentDepth) {
  223. if (currentDepth === generation) {
  224. descendants.push(node);
  225. return;
  226. }
  227. node.childNodes.forEach((child) => findDescendants(child, currentDepth + 1));
  228. }
  229. findDescendants(element, 0);
  230. return descendants;
  231. }
  232. const form = document.querySelector("form");
  233. if (!form)
  234. return;
  235. const seventhGenerationDescendants = getNthGenerationDescendants(form, 7);
  236. if (seventhGenerationDescendants.length === 0 || seventhGenerationDescendants[0].nodeName !== "BUTTON")
  237. return;
  238. return seventhGenerationDescendants[0];
  239. }
  240. function getNewStopGeneratingButton() {
  241. const stopButtonNotLogin = document.querySelector('button[aria-label="Stop generating"]');
  242. const stopButton = document.querySelector('button[data-testid$="stop-button"]');
  243. return stopButtonNotLogin || stopButton;
  244. }
  245. function getStopGeneratingButton() {
  246. return getNewStopGeneratingButton() || getButton("stop");
  247. }
  248. function getResponseElementHTMLs() {
  249. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  250. }
  251. function getLastResponseElement() {
  252. const responseElements = document.querySelectorAll(".group.w-full");
  253. return responseElements[responseElements.length - 1];
  254. }
  255. function getLastResponse() {
  256. const lastResponseElement = getLastResponseElement();
  257. if (!lastResponseElement)
  258. return;
  259. const lastResponse = lastResponseElement.textContent;
  260. return lastResponse;
  261. }
  262. function getTextareaValue() {
  263. var _a;
  264. return ((_a = getTextarea2()) == null ? void 0 : _a.value) || "";
  265. }
  266. function setTextarea(message) {
  267. const textarea = getTextarea2();
  268. if (!textarea)
  269. return;
  270. textarea.value = message;
  271. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  272. }
  273. function send(message) {
  274. return __async(this, null, function* () {
  275. var _a;
  276. setTextarea(message);
  277. const textarea = getTextarea2();
  278. if (!textarea)
  279. return;
  280. (_a = getSubmitButton()) == null ? void 0 : _a.click();
  281. for (let i = 0; i < 10; i++) {
  282. if (isGenerating2()) {
  283. break;
  284. }
  285. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  286. }
  287. });
  288. }
  289. function regenerate() {
  290. const regenerateButton = getRegenerateButton2();
  291. if (!regenerateButton)
  292. return;
  293. regenerateButton.click();
  294. }
  295. function onSend(callback) {
  296. const textarea = getTextarea2();
  297. if (!textarea)
  298. return;
  299. textarea.addEventListener("keydown", function(event) {
  300. if (event.key === "Enter" && !event.shiftKey) {
  301. callback();
  302. }
  303. });
  304. const sendButton = getSubmitButton();
  305. if (!sendButton)
  306. return;
  307. sendButton.addEventListener("mousedown", callback);
  308. }
  309. function isGenerating2() {
  310. var _a, _b;
  311. if (getNewStopGeneratingButton()) {
  312. return true;
  313. }
  314. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  315. }
  316. function waitForIdle() {
  317. return new Promise((resolve) => {
  318. const interval = setInterval(() => {
  319. if (!isGenerating2()) {
  320. clearInterval(interval);
  321. resolve();
  322. }
  323. }, 1e3);
  324. });
  325. }
  326. function sendArray(messages) {
  327. return __async(this, null, function* () {
  328. var _a, _b;
  329. let firstTime = true;
  330. const isLong = messages.length > 60;
  331. let stop = false;
  332. while (messages.length > 0 || stop) {
  333. stop = false;
  334. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  335. if (!firstTime) {
  336. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  337. }
  338. firstTime = false;
  339. if (isGenerating2()) {
  340. continue;
  341. } else if (getContinueGeneratingButton2()) {
  342. (_a = getContinueGeneratingButton2()) == null ? void 0 : _a.click();
  343. stop = true;
  344. continue;
  345. } else if (getRegenerateButton2() && !getTextarea2()) {
  346. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  347. (_b = getRegenerateButton2()) == null ? void 0 : _b.click();
  348. stop = true;
  349. continue;
  350. }
  351. if (messages.length === 0) {
  352. break;
  353. }
  354. yield send(messages.shift() || "");
  355. }
  356. });
  357. }
  358. function setPromptListener(key = "prompt_texts") {
  359. let last_trigger_time = +/* @__PURE__ */ new Date();
  360. if (location.href.includes("chatgpt.com")) {
  361. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  362. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  363. return;
  364. }
  365. last_trigger_time = +/* @__PURE__ */ new Date();
  366. setTimeout(() => __async(this, null, function* () {
  367. sendArray(new_value);
  368. GM_setValue(key, []);
  369. }), 0);
  370. }));
  371. }
  372. }
  373. function getConversation() {
  374. var _a, _b;
  375. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  376. }
  377. function getModelSelectButton() {
  378. const conversation = getConversation();
  379. if (!conversation)
  380. return;
  381. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  382. var _a;
  383. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  384. });
  385. }
  386. function getNewModelSelectButtons() {
  387. return Array.from(document.querySelectorAll("[class^='group/button']"));
  388. }
  389. function hasNewModelSelectButtons() {
  390. return getNewModelSelectButtons().length > 0;
  391. }
  392. function isConversationStarted() {
  393. return !getModelSelectButton();
  394. }
  395. function setPureConversation() {
  396. const conversation = getConversation();
  397. if (!conversation)
  398. return;
  399. const firstChild = conversation.firstChild;
  400. if (!firstChild)
  401. return;
  402. const newDiv = document.createElement("div");
  403. conversation.insertBefore(newDiv, firstChild.nextSibling);
  404. }
  405. function isHorizontalConversation() {
  406. const conversation = getConversation();
  407. if (!conversation)
  408. return true;
  409. if (!isConversationStarted())
  410. return true;
  411. return conversation.classList.contains("grid");
  412. }
  413. function setHorizontalConversation() {
  414. if (isHorizontalConversation())
  415. return;
  416. setPureConversation();
  417. const conversation = getConversation();
  418. if (!conversation)
  419. return;
  420. conversation.classList.remove("flex", "flex-col", "items-center");
  421. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  422. }
  423. function getShareChatButton() {
  424. return document.querySelector('button[aria-label="Share chat"]');
  425. }
  426. function getCopyLinkButton() {
  427. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  428. var _a;
  429. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  430. })[0];
  431. }
  432. }
  433. });
  434.  
  435. // ../../packages/chatkit/chatgpt.js
  436. var require_chatgpt2 = __commonJS({
  437. "../../packages/chatkit/chatgpt.js"(exports, module) {
  438. module.exports = require_chatgpt();
  439. }
  440. });
  441.  
  442. // src/index.ts
  443. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  444. var retryCount = 0;
  445. var maxRetries = 3;
  446. var lastRetryTime = null;
  447. function initialize() {
  448. return __async(this, null, function* () {
  449. yield new Promise((resolve) => window.addEventListener("load", resolve));
  450. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  451. });
  452. }
  453. function main() {
  454. return __async(this, null, function* () {
  455. yield initialize();
  456. let firstTime = true;
  457. setInterval(() => __async(this, null, function* () {
  458. var _a, _b;
  459. const currentTime = (/* @__PURE__ */ new Date()).getTime();
  460. if (lastRetryTime && currentTime - lastRetryTime >= 5 * 60 * 1e3) {
  461. retryCount = 0;
  462. }
  463. while (true) {
  464. const waitTime = !document.hasFocus() ? 20 * 1e3 : 2e3;
  465. if (!firstTime) {
  466. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  467. }
  468. if (!firstTime && (0, import_chatgpt.isGenerating)()) {
  469. continue;
  470. } else if ((0, import_chatgpt.getContinueGeneratingButton)()) {
  471. (_a = (0, import_chatgpt.getContinueGeneratingButton)()) == null ? void 0 : _a.click();
  472. continue;
  473. } else if ((0, import_chatgpt.getRegenerateButton)() && !(0, import_chatgpt.getTextarea)()) {
  474. if (retryCount < maxRetries) {
  475. yield new Promise((resolve) => setTimeout(resolve, 2 * 1e3));
  476. (_b = (0, import_chatgpt.getRegenerateButton)()) == null ? void 0 : _b.click();
  477. retryCount++;
  478. lastRetryTime = (/* @__PURE__ */ new Date()).getTime();
  479. continue;
  480. } else {
  481. console.error("Failed to regenerate after 3 attempts. Stopping retries.");
  482. break;
  483. }
  484. }
  485. firstTime = false;
  486. break;
  487. }
  488. }), 1e3);
  489. });
  490. }
  491. (function() {
  492. main();
  493. })();
  494. })();

QingJ © 2025

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