ChatGPT无限

无限自动询问ChatGPT

当前为 2024-01-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name chatgpt-infinite
  3. // @namespace https://github.com/mefengl
  4. // @version 0.5.18
  5. // @description Infinite auto ask for chatgpt
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  7. // @author mefengl
  8. // @match https://chat.openai.com/*
  9. // @grant none
  10. // @license MIT
  11.  
  12. // @name:en ChatGPT Infinite
  13. // @description:en Infinite auto ask for chatgpt
  14. // @name:zh-CN ChatGPT无限
  15. // @description:zh-CN 无限自动询问ChatGPT
  16. // @name:es ChatGPT Infinito
  17. // @description:es Preguntas automáticas infinitas para chatgpt
  18. // @name:hi चैटजीपीटी अनंत
  19. // @description:hi चैटजीपीटी के लिए अनंत स्वचालित पूछताछ
  20. // @name:ar ChatGPT لانهائي
  21. // @description:ar طلب تلقائي لا نهائي لـ chatgpt
  22. // @name:pt ChatGPT Infinito
  23. // @description:pt Perguntas automáticas infinitas para chatgpt
  24. // @name:ru ChatGPT Бесконечный
  25. // @description:ru Бесконечный автоматический запрос для chatgpt
  26. // @name:ja ChatGPTインフィニティ
  27. // @description:ja ChatGPTの無限自動質問
  28. // @name:de ChatGPT Unendlich
  29. // @description:de Unendliches automatisches Fragen für ChatGPT
  30. // @name:fr ChatGPT Infini
  31. // @description:fr Questions automatiques infinies pour 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. clickFollowUpButton: () => clickFollowUpButton,
  105. getButton: () => getButton,
  106. getContinueGeneratingButton: () => getContinueGeneratingButton,
  107. getConversation: () => getConversation,
  108. getCopyLinkButton: () => getCopyLinkButton,
  109. getFollowUpButtons: () => getFollowUpButtons,
  110. getHistoryBlockTitle: () => getHistoryBlockTitle,
  111. getHistoryBlocks: () => getHistoryBlocks,
  112. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  113. getInitialButtons: () => getInitialButtons,
  114. getLastResponse: () => getLastResponse2,
  115. getLastResponseElement: () => getLastResponseElement,
  116. getModelSelectButton: () => getModelSelectButton,
  117. getNav: () => getNav,
  118. getNewModelSelectButtons: () => getNewModelSelectButtons,
  119. getRegenerateButton: () => getRegenerateButton,
  120. getResponseElementHTMLs: () => getResponseElementHTMLs,
  121. getShareChatButton: () => getShareChatButton,
  122. getStopGeneratingButton: () => getStopGeneratingButton,
  123. getSubmitButton: () => getSubmitButton,
  124. getTextarea: () => getTextarea,
  125. getTextareaValue: () => getTextareaValue,
  126. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  127. isConversationStarted: () => isConversationStarted,
  128. isGenerating: () => isGenerating,
  129. isHorizontalConversation: () => isHorizontalConversation,
  130. onSend: () => onSend,
  131. regenerate: () => regenerate,
  132. send: () => send2,
  133. sendArray: () => sendArray,
  134. setHorizontalConversation: () => setHorizontalConversation,
  135. setPromptListener: () => setPromptListener,
  136. setPureConversation: () => setPureConversation,
  137. setTextarea: () => setTextarea,
  138. waitForIdle: () => waitForIdle2
  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 getTextarea() {
  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 = getTextarea();
  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. return Array.from(document.querySelectorAll('button[as="button"]')).find((button) => {
  203. var _a;
  204. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  205. });
  206. }
  207. function getRegenerateButton() {
  208. return getButton("regenerate");
  209. }
  210. function getContinueGeneratingButton() {
  211. return getButton("continue");
  212. }
  213. function getNewStopGeneratingButton() {
  214. return document.querySelector('button[aria-label="Stop generating"]');
  215. }
  216. function getStopGeneratingButton() {
  217. return getNewStopGeneratingButton() || getButton("stop");
  218. }
  219. function getResponseElementHTMLs() {
  220. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  221. }
  222. function getLastResponseElement() {
  223. const responseElements = document.querySelectorAll(".group.w-full");
  224. return responseElements[responseElements.length - 1];
  225. }
  226. function getLastResponse2() {
  227. const lastResponseElement = getLastResponseElement();
  228. if (!lastResponseElement)
  229. return;
  230. const lastResponse = lastResponseElement.textContent;
  231. return lastResponse;
  232. }
  233. function getTextareaValue() {
  234. var _a;
  235. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  236. }
  237. function setTextarea(message) {
  238. const textarea = getTextarea();
  239. if (!textarea)
  240. return;
  241. textarea.value = message;
  242. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  243. }
  244. function send2(message) {
  245. return __async(this, null, function* () {
  246. var _a;
  247. setTextarea(message);
  248. const textarea = getTextarea();
  249. if (!textarea)
  250. return;
  251. while (textarea.value === message) {
  252. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  253. (_a = getSubmitButton()) == null ? void 0 : _a.click();
  254. yield new Promise((resolve) => setTimeout(resolve, 100));
  255. }
  256. for (let i = 0; i < 10; i++) {
  257. if (isGenerating()) {
  258. break;
  259. }
  260. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  261. }
  262. });
  263. }
  264. function regenerate() {
  265. const regenerateButton = getRegenerateButton();
  266. if (!regenerateButton)
  267. return;
  268. regenerateButton.click();
  269. }
  270. function onSend(callback) {
  271. const textarea = getTextarea();
  272. if (!textarea)
  273. return;
  274. textarea.addEventListener("keydown", function(event) {
  275. if (event.key === "Enter" && !event.shiftKey) {
  276. callback();
  277. }
  278. });
  279. const sendButton = getSubmitButton();
  280. if (!sendButton)
  281. return;
  282. sendButton.addEventListener("mousedown", callback);
  283. }
  284. function isGenerating() {
  285. var _a, _b;
  286. if (getNewStopGeneratingButton()) {
  287. return true;
  288. }
  289. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  290. }
  291. function waitForIdle2() {
  292. return new Promise((resolve) => {
  293. const interval = setInterval(() => {
  294. if (!isGenerating()) {
  295. clearInterval(interval);
  296. resolve();
  297. }
  298. }, 1e3);
  299. });
  300. }
  301. function sendArray(messages) {
  302. return __async(this, null, function* () {
  303. var _a, _b;
  304. let firstTime = true;
  305. const isLong = messages.length > 60;
  306. while (messages.length > 0) {
  307. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  308. if (!firstTime) {
  309. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  310. }
  311. if (isGenerating()) {
  312. continue;
  313. } else if (getContinueGeneratingButton()) {
  314. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  315. continue;
  316. } else if (getRegenerateButton() && !getTextarea()) {
  317. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  318. (_b = getRegenerateButton()) == null ? void 0 : _b.click();
  319. continue;
  320. }
  321. firstTime = false;
  322. if (messages.length === 0) {
  323. break;
  324. }
  325. yield send2(messages.shift() || "");
  326. }
  327. });
  328. }
  329. function setPromptListener(key = "prompt_texts") {
  330. let last_trigger_time = +/* @__PURE__ */ new Date();
  331. if (location.href.includes("chat.openai")) {
  332. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  333. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  334. return;
  335. }
  336. last_trigger_time = +/* @__PURE__ */ new Date();
  337. setTimeout(() => __async(this, null, function* () {
  338. sendArray(new_value);
  339. GM_setValue(key, []);
  340. }), 0);
  341. }));
  342. }
  343. }
  344. function getConversation() {
  345. var _a, _b;
  346. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  347. }
  348. function getModelSelectButton() {
  349. const conversation = getConversation();
  350. if (!conversation)
  351. return;
  352. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  353. var _a;
  354. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  355. });
  356. }
  357. function getNewModelSelectButtons() {
  358. return Array.from(document.querySelectorAll("[class^='group/button']"));
  359. }
  360. function hasNewModelSelectButtons() {
  361. return getNewModelSelectButtons().length > 0;
  362. }
  363. function isConversationStarted() {
  364. return !getModelSelectButton();
  365. }
  366. function setPureConversation() {
  367. const conversation = getConversation();
  368. if (!conversation)
  369. return;
  370. const firstChild = conversation.firstChild;
  371. if (!firstChild)
  372. return;
  373. const newDiv = document.createElement("div");
  374. conversation.insertBefore(newDiv, firstChild.nextSibling);
  375. }
  376. function isHorizontalConversation() {
  377. const conversation = getConversation();
  378. if (!conversation)
  379. return true;
  380. if (!isConversationStarted())
  381. return true;
  382. return conversation.classList.contains("grid");
  383. }
  384. function setHorizontalConversation() {
  385. if (isHorizontalConversation())
  386. return;
  387. setPureConversation();
  388. const conversation = getConversation();
  389. if (!conversation)
  390. return;
  391. conversation.classList.remove("flex", "flex-col", "items-center");
  392. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  393. }
  394. function getShareChatButton() {
  395. return document.querySelector('button[aria-label="Share chat"]');
  396. }
  397. function getCopyLinkButton() {
  398. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  399. var _a;
  400. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  401. })[0];
  402. }
  403. }
  404. });
  405.  
  406. // ../../packages/chatkit/chatgpt.js
  407. var require_chatgpt2 = __commonJS({
  408. "../../packages/chatkit/chatgpt.js"(exports, module) {
  409. module.exports = require_chatgpt();
  410. }
  411. });
  412.  
  413. // src/askForLanguage/index.ts
  414. function askForLanguage() {
  415. return __async(this, null, function* () {
  416. return prompt("What language do you want to use?");
  417. });
  418. }
  419.  
  420. // src/infiniteLoop/index.ts
  421. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  422. function startInfiniteLoop() {
  423. return __async(this, null, function* () {
  424. const language = yield askForLanguage();
  425. if (!language)
  426. return;
  427. (0, import_chatgpt.send)(`you can only answer question in ${language} language`);
  428. yield (0, import_chatgpt.waitForIdle)();
  429. while (true) {
  430. const lastResponse = (0, import_chatgpt.getLastResponse)();
  431. const question = extractQuestion(lastResponse);
  432. yield (0, import_chatgpt.send)(question + "\nanswer above question in 1000 words, and show me one more further question I can ask in the end prefixed with Q:");
  433. yield (0, import_chatgpt.waitForIdle)();
  434. yield sleep(3e3);
  435. }
  436. });
  437. }
  438. function extractQuestion(text) {
  439. return text.split("Q:").pop().trim();
  440. }
  441. function sleep(ms) {
  442. return new Promise((resolve) => setTimeout(resolve, ms));
  443. }
  444. var infiniteLoop_default = startInfiniteLoop;
  445.  
  446. // src/index.ts
  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. infiniteLoop_default();
  457. });
  458. }
  459. (function() {
  460. main();
  461. })();
  462. })();