ChatGPT 自动继续 🔄

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

当前为 2023-05-29 提交的版本,查看 最新版本

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