ChatGPT 自动继续 🔄

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

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

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