Greasy Fork 还支持 简体中文。

ChatGPT Auto-Continue 🔄

⚡ Automatically click the 'Continue Generating' button in ChatGPT!

目前為 2023-07-26 提交的版本,檢視 最新版本

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