ChatGPT无限

无限自动询问ChatGPT

当前为 2023-08-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name chatgpt-infinite
  3. // @namespace https://github.com/mefengl
  4. // @version 0.5.9
  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. setHorizontalConversation: () => setHorizontalConversation,
  134. setPromptListener: () => setPromptListener,
  135. setPureConversation: () => setPureConversation,
  136. setTextarea: () => setTextarea,
  137. waitForIdle: () => waitForIdle2
  138. });
  139. module.exports = __toCommonJS(chatgpt_exports);
  140. function getNav() {
  141. return document.querySelector("nav");
  142. }
  143. function getHistoryBlocks() {
  144. const nav = getNav();
  145. if (!nav)
  146. return [];
  147. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  148. return result;
  149. }
  150. function getHistoryBlockTitle(historyBlock) {
  151. var _a;
  152. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  153. }
  154. function getHistoryBlocksWithTitle() {
  155. const historyBlocks = getHistoryBlocks();
  156. const result = historyBlocks.map((historyBlock) => ({
  157. block: historyBlock,
  158. title: getHistoryBlockTitle(historyBlock)
  159. }));
  160. return result;
  161. }
  162. function getTextarea() {
  163. const form = document.querySelector("form");
  164. if (!form)
  165. return;
  166. const textareas = form.querySelectorAll("textarea");
  167. const result = textareas[0];
  168. return result;
  169. }
  170. function getSubmitButton() {
  171. const textarea = getTextarea();
  172. if (!textarea)
  173. return;
  174. return textarea.nextElementSibling;
  175. }
  176. function getInitialButtons() {
  177. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => button.querySelectorAll(".truncate").length === 2);
  178. }
  179. function getFollowUpButtons() {
  180. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  181. var _a;
  182. return (_a = button.textContent) == null ? void 0 : _a.trim().match(/[.!?]$/);
  183. });
  184. }
  185. function clickFollowUpButton(index) {
  186. const followUpButtons = getFollowUpButtons();
  187. if (followUpButtons.length === 0)
  188. return;
  189. if (index === void 0 || index < 0 || index >= followUpButtons.length) {
  190. index = Math.floor(Math.random() * followUpButtons.length);
  191. }
  192. followUpButtons[index].click();
  193. }
  194. function getButton(text) {
  195. return Array.from(document.querySelectorAll('button[as="button"]')).find((button) => {
  196. var _a;
  197. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  198. });
  199. }
  200. function getRegenerateButton() {
  201. return getButton("regenerate");
  202. }
  203. function getContinueGeneratingButton() {
  204. return getButton("continue");
  205. }
  206. function getStopGeneratingButton() {
  207. return getButton("stop");
  208. }
  209. function getResponseElementHTMLs() {
  210. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  211. }
  212. function getLastResponseElement() {
  213. const responseElements = document.querySelectorAll(".group.w-full");
  214. return responseElements[responseElements.length - 1];
  215. }
  216. function getLastResponse2() {
  217. const lastResponseElement = getLastResponseElement();
  218. if (!lastResponseElement)
  219. return;
  220. const lastResponse = lastResponseElement.textContent;
  221. return lastResponse;
  222. }
  223. function getTextareaValue() {
  224. var _a;
  225. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  226. }
  227. function setTextarea(message) {
  228. const textarea = getTextarea();
  229. if (!textarea)
  230. return;
  231. textarea.value = message;
  232. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  233. }
  234. function send2(message) {
  235. return __async(this, null, function* () {
  236. setTextarea(message);
  237. const textarea = getTextarea();
  238. if (!textarea)
  239. return;
  240. while (textarea.value === message) {
  241. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  242. yield new Promise((resolve) => setTimeout(resolve, 100));
  243. }
  244. });
  245. }
  246. function regenerate() {
  247. const regenerateButton = getRegenerateButton();
  248. if (!regenerateButton)
  249. return;
  250. regenerateButton.click();
  251. }
  252. function onSend(callback) {
  253. const textarea = getTextarea();
  254. if (!textarea)
  255. return;
  256. textarea.addEventListener("keydown", function(event) {
  257. if (event.key === "Enter" && !event.shiftKey) {
  258. callback();
  259. }
  260. });
  261. const sendButton = getSubmitButton();
  262. if (!sendButton)
  263. return;
  264. sendButton.addEventListener("mousedown", callback);
  265. }
  266. function isGenerating() {
  267. var _a, _b;
  268. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  269. }
  270. function waitForIdle2() {
  271. return new Promise((resolve) => {
  272. const interval = setInterval(() => {
  273. if (!isGenerating()) {
  274. clearInterval(interval);
  275. resolve();
  276. }
  277. }, 1e3);
  278. });
  279. }
  280. function setPromptListener(key = "prompt_texts") {
  281. let last_trigger_time = +/* @__PURE__ */ new Date();
  282. if (location.href.includes("chat.openai")) {
  283. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  284. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  285. return;
  286. }
  287. last_trigger_time = +/* @__PURE__ */ new Date();
  288. setTimeout(() => __async(this, null, function* () {
  289. var _a, _b;
  290. const prompt_texts = new_value;
  291. const isLong = prompt_texts.length > 60;
  292. if (prompt_texts.length > 0) {
  293. let firstTime = true;
  294. while (true) {
  295. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  296. if (!firstTime) {
  297. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  298. }
  299. if (!firstTime && isGenerating()) {
  300. continue;
  301. } else if (getContinueGeneratingButton()) {
  302. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  303. continue;
  304. } else if (getRegenerateButton() && !getTextarea()) {
  305. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  306. (_b = getRegenerateButton()) == null ? void 0 : _b.click();
  307. continue;
  308. }
  309. firstTime = false;
  310. if (prompt_texts.length === 0) {
  311. break;
  312. }
  313. yield send2(prompt_texts.shift() || "");
  314. }
  315. }
  316. }), 0);
  317. GM_setValue(key, []);
  318. }));
  319. }
  320. }
  321. function getConversation() {
  322. var _a, _b;
  323. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  324. }
  325. function getModelSelectButton() {
  326. const conversation = getConversation();
  327. if (!conversation)
  328. return;
  329. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  330. var _a;
  331. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  332. });
  333. }
  334. function getNewModelSelectButtons() {
  335. return Array.from(document.querySelectorAll("[class^='group/button']"));
  336. }
  337. function hasNewModelSelectButtons() {
  338. return getNewModelSelectButtons().length > 0;
  339. }
  340. function isConversationStarted() {
  341. return !getModelSelectButton();
  342. }
  343. function setPureConversation() {
  344. const conversation = getConversation();
  345. if (!conversation)
  346. return;
  347. const firstChild = conversation.firstChild;
  348. if (!firstChild)
  349. return;
  350. const newDiv = document.createElement("div");
  351. conversation.insertBefore(newDiv, firstChild.nextSibling);
  352. }
  353. function isHorizontalConversation() {
  354. const conversation = getConversation();
  355. if (!conversation)
  356. return true;
  357. if (!isConversationStarted())
  358. return true;
  359. return conversation.classList.contains("grid");
  360. }
  361. function setHorizontalConversation() {
  362. if (isHorizontalConversation())
  363. return;
  364. setPureConversation();
  365. const conversation = getConversation();
  366. if (!conversation)
  367. return;
  368. conversation.classList.remove("flex", "flex-col", "items-center");
  369. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  370. }
  371. function getShareChatButton() {
  372. return document.querySelector('button[aria-label="Share chat"]');
  373. }
  374. function getCopyLinkButton() {
  375. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  376. var _a;
  377. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  378. })[0];
  379. }
  380. }
  381. });
  382.  
  383. // ../../packages/chatkit/chatgpt.js
  384. var require_chatgpt2 = __commonJS({
  385. "../../packages/chatkit/chatgpt.js"(exports, module) {
  386. module.exports = require_chatgpt();
  387. }
  388. });
  389.  
  390. // src/askForLanguage/index.ts
  391. function askForLanguage() {
  392. return __async(this, null, function* () {
  393. return prompt("What language do you want to use?");
  394. });
  395. }
  396.  
  397. // src/infiniteLoop/index.ts
  398. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  399. function startInfiniteLoop() {
  400. return __async(this, null, function* () {
  401. const language = yield askForLanguage();
  402. if (!language)
  403. return;
  404. (0, import_chatgpt.send)(`you can only answer question in ${language} language`);
  405. yield (0, import_chatgpt.waitForIdle)();
  406. while (true) {
  407. const lastResponse = (0, import_chatgpt.getLastResponse)();
  408. const question = extractQuestion(lastResponse);
  409. 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:");
  410. yield (0, import_chatgpt.waitForIdle)();
  411. yield sleep(3e3);
  412. }
  413. });
  414. }
  415. function extractQuestion(text) {
  416. return text.split("Q:").pop().trim();
  417. }
  418. function sleep(ms) {
  419. return new Promise((resolve) => setTimeout(resolve, ms));
  420. }
  421. var infiniteLoop_default = startInfiniteLoop;
  422.  
  423. // src/index.ts
  424. function initialize() {
  425. return __async(this, null, function* () {
  426. yield new Promise((resolve) => window.addEventListener("load", resolve));
  427. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  428. });
  429. }
  430. function main() {
  431. return __async(this, null, function* () {
  432. yield initialize();
  433. infiniteLoop_default();
  434. });
  435. }
  436. (function() {
  437. main();
  438. })();
  439. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址