ChatGPT 自动继续 🔄

⚡ 自动点击ChatGPT中的“继续生成”按钮!

当前为 2023-07-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ChatGPT Auto-Continue 🔄
  3. // @description ⚡ Automatically click the 'Continue Generating' button in ChatGPT!
  4. // @author mefengl
  5. // @version 0.0.13
  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://chat.openai.com/*
  10. // @grant none
  11.  
  12. // @name:en ChatGPT Auto-Continue 🔄
  13. // @description:en ⚡ Automatically click the 'Continue Generating' button in ChatGPT!
  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!
  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!
  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!
  30. // @name:fr ChatGPT Auto-Continuer 🔄
  31. // @description:fr ⚡ Cliquez automatiquement sur le bouton 'Continuer à générer' dans ChatGPT!
  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. getButton: () => getButton,
  105. getContinueGeneratingButton: () => getContinueGeneratingButton2,
  106. getConversation: () => getConversation,
  107. getCopyLinkButton: () => getCopyLinkButton,
  108. getHistoryBlockTitle: () => getHistoryBlockTitle,
  109. getHistoryBlocks: () => getHistoryBlocks,
  110. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  111. getLastResponse: () => getLastResponse,
  112. getLastResponseElement: () => getLastResponseElement,
  113. getModelSelectButton: () => getModelSelectButton,
  114. getNav: () => getNav,
  115. getNewModelSelectButtons: () => getNewModelSelectButtons,
  116. getRegenerateButton: () => getRegenerateButton,
  117. getResponseElementHTMLs: () => getResponseElementHTMLs,
  118. getShareChatButton: () => getShareChatButton,
  119. getStopGeneratingButton: () => getStopGeneratingButton,
  120. getSubmitButton: () => getSubmitButton,
  121. getTextarea: () => getTextarea,
  122. getTextareaValue: () => getTextareaValue,
  123. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  124. isConversationStarted: () => isConversationStarted,
  125. isGenerating: () => isGenerating,
  126. isHorizontalConversation: () => isHorizontalConversation,
  127. onSend: () => onSend,
  128. regenerate: () => regenerate,
  129. send: () => send,
  130. setHorizontalConversation: () => setHorizontalConversation,
  131. setPromptListener: () => setPromptListener,
  132. setPureConversation: () => setPureConversation,
  133. setTextarea: () => setTextarea,
  134. waitForIdle: () => waitForIdle
  135. });
  136. module.exports = __toCommonJS(chatgpt_exports);
  137. function getNav() {
  138. return document.querySelector("nav");
  139. }
  140. function getHistoryBlocks() {
  141. const nav = getNav();
  142. if (!nav)
  143. return [];
  144. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  145. return result;
  146. }
  147. function getHistoryBlockTitle(historyBlock) {
  148. var _a;
  149. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  150. }
  151. function getHistoryBlocksWithTitle() {
  152. const historyBlocks = getHistoryBlocks();
  153. const result = historyBlocks.map((historyBlock) => ({
  154. block: historyBlock,
  155. title: getHistoryBlockTitle(historyBlock)
  156. }));
  157. return result;
  158. }
  159. function getTextarea() {
  160. const form = document.querySelector("form");
  161. if (!form)
  162. return;
  163. const textareas = form.querySelectorAll("textarea");
  164. const result = textareas[0];
  165. return result;
  166. }
  167. function getSubmitButton() {
  168. const textarea = getTextarea();
  169. if (!textarea)
  170. return;
  171. return textarea.nextElementSibling;
  172. }
  173. function getButton(text) {
  174. return Array.from(document.querySelectorAll('button[as="button"]')).find((button) => {
  175. var _a;
  176. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  177. });
  178. }
  179. function getRegenerateButton() {
  180. return getButton("regenerate");
  181. }
  182. function getContinueGeneratingButton2() {
  183. return getButton("continue");
  184. }
  185. function getStopGeneratingButton() {
  186. return getButton("stop");
  187. }
  188. function getResponseElementHTMLs() {
  189. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  190. }
  191. function getLastResponseElement() {
  192. const responseElements = document.querySelectorAll(".group.w-full");
  193. return responseElements[responseElements.length - 1];
  194. }
  195. function getLastResponse() {
  196. const lastResponseElement = getLastResponseElement();
  197. if (!lastResponseElement)
  198. return;
  199. const lastResponse = lastResponseElement.textContent;
  200. return lastResponse;
  201. }
  202. function getTextareaValue() {
  203. var _a;
  204. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  205. }
  206. function setTextarea(message) {
  207. const textarea = getTextarea();
  208. if (!textarea)
  209. return;
  210. textarea.value = message;
  211. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  212. }
  213. function send(message) {
  214. return __async(this, null, function* () {
  215. setTextarea(message);
  216. const textarea = getTextarea();
  217. if (!textarea)
  218. return;
  219. while (textarea.value === message) {
  220. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  221. yield new Promise((resolve) => setTimeout(resolve, 100));
  222. }
  223. });
  224. }
  225. function regenerate() {
  226. const regenerateButton = getRegenerateButton();
  227. if (!regenerateButton)
  228. return;
  229. regenerateButton.click();
  230. }
  231. function onSend(callback) {
  232. const textarea = getTextarea();
  233. if (!textarea)
  234. return;
  235. textarea.addEventListener("keydown", function(event) {
  236. if (event.key === "Enter" && !event.shiftKey) {
  237. callback();
  238. }
  239. });
  240. const sendButton = getSubmitButton();
  241. if (!sendButton)
  242. return;
  243. sendButton.addEventListener("mousedown", callback);
  244. }
  245. function isGenerating() {
  246. var _a, _b;
  247. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  248. }
  249. function waitForIdle() {
  250. return new Promise((resolve) => {
  251. const interval = setInterval(() => {
  252. if (!isGenerating()) {
  253. clearInterval(interval);
  254. resolve();
  255. }
  256. }, 1e3);
  257. });
  258. }
  259. function setPromptListener(key = "prompt_texts") {
  260. let last_trigger_time = +/* @__PURE__ */ new Date();
  261. if (location.href.includes("chat.openai")) {
  262. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  263. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  264. return;
  265. }
  266. last_trigger_time = +/* @__PURE__ */ new Date();
  267. setTimeout(() => __async(this, null, function* () {
  268. var _a, _b;
  269. const prompt_texts = new_value;
  270. const isLong = prompt_texts.length > 60;
  271. if (prompt_texts.length > 0) {
  272. let firstTime = true;
  273. while (prompt_texts.length > 0) {
  274. const waitTime = isLong && !document.hasFocus() ? 30 * 1e3 : 2e3;
  275. if (!firstTime) {
  276. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  277. }
  278. if (!firstTime && isGenerating()) {
  279. continue;
  280. } else if (getContinueGeneratingButton2()) {
  281. (_a = getContinueGeneratingButton2()) == null ? void 0 : _a.click();
  282. continue;
  283. } else if (getRegenerateButton() && !getTextarea()) {
  284. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  285. (_b = getRegenerateButton()) == null ? void 0 : _b.click();
  286. continue;
  287. }
  288. firstTime = false;
  289. yield send(prompt_texts.shift() || "");
  290. }
  291. }
  292. }), 0);
  293. GM_setValue(key, []);
  294. }));
  295. }
  296. }
  297. function getConversation() {
  298. var _a, _b;
  299. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  300. }
  301. function getModelSelectButton() {
  302. const conversation = getConversation();
  303. if (!conversation)
  304. return;
  305. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  306. var _a;
  307. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  308. });
  309. }
  310. function getNewModelSelectButtons() {
  311. return Array.from(document.querySelectorAll("[class^='group/button']"));
  312. }
  313. function hasNewModelSelectButtons() {
  314. return getNewModelSelectButtons().length > 0;
  315. }
  316. function isConversationStarted() {
  317. return !getModelSelectButton();
  318. }
  319. function setPureConversation() {
  320. const conversation = getConversation();
  321. if (!conversation)
  322. return;
  323. const firstChild = conversation.firstChild;
  324. if (!firstChild)
  325. return;
  326. const newDiv = document.createElement("div");
  327. conversation.insertBefore(newDiv, firstChild.nextSibling);
  328. }
  329. function isHorizontalConversation() {
  330. const conversation = getConversation();
  331. if (!conversation)
  332. return true;
  333. if (!isConversationStarted())
  334. return true;
  335. return conversation.classList.contains("grid");
  336. }
  337. function setHorizontalConversation() {
  338. if (isHorizontalConversation())
  339. return;
  340. setPureConversation();
  341. const conversation = getConversation();
  342. if (!conversation)
  343. return;
  344. conversation.classList.remove("flex", "flex-col", "items-center");
  345. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  346. }
  347. function getShareChatButton() {
  348. return document.querySelector('button[aria-label="Share chat"]');
  349. }
  350. function getCopyLinkButton() {
  351. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  352. var _a;
  353. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  354. })[0];
  355. }
  356. }
  357. });
  358.  
  359. // ../../packages/chatkit/chatgpt.js
  360. var require_chatgpt2 = __commonJS({
  361. "../../packages/chatkit/chatgpt.js"(exports, module) {
  362. module.exports = require_chatgpt();
  363. }
  364. });
  365.  
  366. // src/index.ts
  367. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  368. function initialize() {
  369. return __async(this, null, function* () {
  370. yield new Promise((resolve) => window.addEventListener("load", resolve));
  371. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  372. });
  373. }
  374. function main() {
  375. return __async(this, null, function* () {
  376. yield initialize();
  377. setInterval(() => __async(this, null, function* () {
  378. const continueGeneratingButton = (0, import_chatgpt.getContinueGeneratingButton)();
  379. if (continueGeneratingButton) {
  380. continueGeneratingButton.click();
  381. }
  382. }), 1e3);
  383. });
  384. }
  385. (function() {
  386. main();
  387. })();
  388. })();