聊天章鱼

🐙 让章鱼为您发送多条信息

当前为 2023-12-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name chat-octopus
  3. // @namespace https://github.com/mefengl
  4. // @version 0.2.34
  5. // @description 🐙 let octopus send multiple messages for you
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  7. // @author mefengl
  8. // @match https://chat.openai.com/*
  9. // @match https://bard.google.com/*
  10. // @match https://www.bing.com/search?q=Bing+AI*
  11. // @require https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js
  12. // @grant GM_openInTab
  13. // @grant GM_registerMenuCommand
  14. // @grant GM_unregisterMenuCommand
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @grant GM_addValueChangeListener
  18. // @license MIT
  19.  
  20. // @name:en Chat Octopus
  21. // @description:en 🐙 let octopus send multiple messages for you
  22. // @name:zh-CN 聊天章鱼
  23. // @description:zh-CN 🐙 让章鱼为您发送多条信息
  24. // @name:es Chat Pulpo
  25. // @description:es 🐙 deja que el pulpo envíe múltiples mensajes por ti
  26. // @name:hi चैट ऑक्टोपस
  27. // @description:hi 🐙 आपके लिए कई संदेश भेजने के लिए ऑक्टोपस की अनुमति दें
  28. // @name:ar أخطبوط الدردشة
  29. // @description:ar 🐙 دع الأخطبوط يرسل رسائل متعددة نيابة عنك
  30. // @name:pt Chat Polvo
  31. // @description:pt 🐙 deixe o polvo enviar várias mensagens para você
  32. // @name:ru Чат-осьминог
  33. // @description:ru 🐙 позвольте осьминогу отправлять несколько сообщений за вас
  34. // @name:ja チャットオクトパス
  35. // @description:ja 🐙 タコがあなたに代わって複数のメッセージを送る
  36. // @name:de Chat-Oktopus
  37. // @description:de 🐙 Lassen Sie den Oktopus mehrere Nachrichten für Sie senden
  38. // @name:fr Chat Poulpe
  39. // @description:fr 🐙 laissez la pieuvre envoyer plusieurs messages pour vous
  40. // ==/UserScript==
  41. "use strict";
  42. (() => {
  43. var __async = (__this, __arguments, generator) => {
  44. return new Promise((resolve, reject) => {
  45. var fulfilled = (value) => {
  46. try {
  47. step(generator.next(value));
  48. } catch (e) {
  49. reject(e);
  50. }
  51. };
  52. var rejected = (value) => {
  53. try {
  54. step(generator.throw(value));
  55. } catch (e) {
  56. reject(e);
  57. }
  58. };
  59. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  60. step((generator = generator.apply(__this, __arguments)).next());
  61. });
  62. };
  63.  
  64. // ../../packages/chatkit/dist/chunk-XT4TKGC2.mjs
  65. var __defProp = Object.defineProperty;
  66. var __export = (target, all) => {
  67. for (var name in all)
  68. __defProp(target, name, { get: all[name], enumerable: true });
  69. };
  70.  
  71. // ../../packages/chatkit/dist/chunk-NDFQ63YR.mjs
  72. var chatgpt_exports = {};
  73. __export(chatgpt_exports, {
  74. clickFollowUpButton: () => clickFollowUpButton,
  75. getButton: () => getButton,
  76. getContinueGeneratingButton: () => getContinueGeneratingButton,
  77. getConversation: () => getConversation,
  78. getCopyLinkButton: () => getCopyLinkButton,
  79. getFollowUpButtons: () => getFollowUpButtons,
  80. getHistoryBlockTitle: () => getHistoryBlockTitle,
  81. getHistoryBlocks: () => getHistoryBlocks,
  82. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  83. getInitialButtons: () => getInitialButtons,
  84. getLastResponse: () => getLastResponse,
  85. getLastResponseElement: () => getLastResponseElement,
  86. getModelSelectButton: () => getModelSelectButton,
  87. getNav: () => getNav,
  88. getNewModelSelectButtons: () => getNewModelSelectButtons,
  89. getRegenerateButton: () => getRegenerateButton,
  90. getResponseElementHTMLs: () => getResponseElementHTMLs,
  91. getShareChatButton: () => getShareChatButton,
  92. getStopGeneratingButton: () => getStopGeneratingButton,
  93. getSubmitButton: () => getSubmitButton,
  94. getTextarea: () => getTextarea,
  95. getTextareaValue: () => getTextareaValue,
  96. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  97. isConversationStarted: () => isConversationStarted,
  98. isGenerating: () => isGenerating,
  99. isHorizontalConversation: () => isHorizontalConversation,
  100. onSend: () => onSend,
  101. regenerate: () => regenerate,
  102. send: () => send,
  103. sendArray: () => sendArray,
  104. setHorizontalConversation: () => setHorizontalConversation,
  105. setPromptListener: () => setPromptListener,
  106. setPureConversation: () => setPureConversation,
  107. setTextarea: () => setTextarea,
  108. waitForIdle: () => waitForIdle
  109. });
  110. function getNav() {
  111. return document.querySelector("nav");
  112. }
  113. function getHistoryBlocks() {
  114. const nav = getNav();
  115. if (!nav)
  116. return [];
  117. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  118. return result;
  119. }
  120. function getHistoryBlockTitle(historyBlock) {
  121. var _a;
  122. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  123. }
  124. function getHistoryBlocksWithTitle() {
  125. const historyBlocks = getHistoryBlocks();
  126. const result = historyBlocks.map((historyBlock) => ({
  127. block: historyBlock,
  128. title: getHistoryBlockTitle(historyBlock)
  129. }));
  130. return result;
  131. }
  132. function getTextarea() {
  133. const form = document.querySelector("form");
  134. if (!form)
  135. return;
  136. const textareas = form.querySelectorAll("textarea");
  137. const result = textareas[0];
  138. return result;
  139. }
  140. function getNewSubmitButton() {
  141. return document.querySelector('button[data-testid="send-button"]');
  142. }
  143. function getSubmitButton() {
  144. if (getNewSubmitButton()) {
  145. return getNewSubmitButton();
  146. }
  147. const textarea = getTextarea();
  148. if (!textarea)
  149. return;
  150. return textarea.nextElementSibling;
  151. }
  152. function getInitialButtons() {
  153. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => button.querySelectorAll(".truncate").length === 2);
  154. }
  155. function getFollowUpButtons() {
  156. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  157. var _a;
  158. return (_a = button.textContent) == null ? void 0 : _a.trim().match(/[.!?]$/);
  159. });
  160. }
  161. function clickFollowUpButton(index) {
  162. const followUpButtons = getFollowUpButtons();
  163. if (followUpButtons.length === 0)
  164. return;
  165. if (index === void 0 || index < 0 || index >= followUpButtons.length) {
  166. index = Math.floor(Math.random() * followUpButtons.length);
  167. }
  168. followUpButtons[index].click();
  169. }
  170. function getButton(text) {
  171. return Array.from(document.querySelectorAll('button[as="button"]')).find((button) => {
  172. var _a;
  173. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  174. });
  175. }
  176. function getRegenerateButton() {
  177. return getButton("regenerate");
  178. }
  179. function getContinueGeneratingButton() {
  180. return getButton("continue");
  181. }
  182. function getNewStopGeneratingButton() {
  183. return document.querySelector('button[aria-label="Stop generating"]');
  184. }
  185. function getStopGeneratingButton() {
  186. return getNewStopGeneratingButton() || getButton("stop");
  187. }
  188. function getResponseElementHTMLs() {
  189. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  190. }
  191. function getLastResponseElement() {
  192. const responseElements = document.querySelectorAll(".group.w-full");
  193. return responseElements[responseElements.length - 1];
  194. }
  195. function getLastResponse() {
  196. const lastResponseElement = getLastResponseElement();
  197. if (!lastResponseElement)
  198. return;
  199. const lastResponse = lastResponseElement.textContent;
  200. return lastResponse;
  201. }
  202. function getTextareaValue() {
  203. var _a;
  204. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  205. }
  206. function setTextarea(message) {
  207. const textarea = getTextarea();
  208. if (!textarea)
  209. return;
  210. textarea.value = message;
  211. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  212. }
  213. function send(message) {
  214. return __async(this, null, function* () {
  215. setTextarea(message);
  216. const textarea = getTextarea();
  217. if (!textarea)
  218. return;
  219. while (textarea.value === message) {
  220. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  221. yield new Promise((resolve) => setTimeout(resolve, 100));
  222. }
  223. for (let i = 0; i < 10; i++) {
  224. if (isGenerating()) {
  225. break;
  226. }
  227. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  228. }
  229. });
  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. if (getNewStopGeneratingButton()) {
  254. return true;
  255. }
  256. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  257. }
  258. function waitForIdle() {
  259. return new Promise((resolve) => {
  260. const interval = setInterval(() => {
  261. if (!isGenerating()) {
  262. clearInterval(interval);
  263. resolve();
  264. }
  265. }, 1e3);
  266. });
  267. }
  268. function sendArray(messages) {
  269. return __async(this, null, function* () {
  270. var _a, _b;
  271. let firstTime = true;
  272. const isLong = messages.length > 60;
  273. while (messages.length > 0) {
  274. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  275. if (!firstTime) {
  276. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  277. }
  278. if (isGenerating()) {
  279. continue;
  280. } else if (getContinueGeneratingButton()) {
  281. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  282. continue;
  283. } else if (getRegenerateButton() && !getTextarea()) {
  284. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  285. (_b = getRegenerateButton()) == null ? void 0 : _b.click();
  286. continue;
  287. }
  288. firstTime = false;
  289. if (messages.length === 0) {
  290. break;
  291. }
  292. yield send(messages.shift() || "");
  293. }
  294. });
  295. }
  296. function setPromptListener(key = "prompt_texts") {
  297. let last_trigger_time = +/* @__PURE__ */ new Date();
  298. if (location.href.includes("chat.openai")) {
  299. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  300. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  301. return;
  302. }
  303. last_trigger_time = +/* @__PURE__ */ new Date();
  304. setTimeout(() => __async(this, null, function* () {
  305. sendArray(new_value);
  306. GM_setValue(key, []);
  307. }), 0);
  308. }));
  309. }
  310. }
  311. function getConversation() {
  312. var _a, _b;
  313. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  314. }
  315. function getModelSelectButton() {
  316. const conversation = getConversation();
  317. if (!conversation)
  318. return;
  319. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  320. var _a;
  321. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  322. });
  323. }
  324. function getNewModelSelectButtons() {
  325. return Array.from(document.querySelectorAll("[class^='group/button']"));
  326. }
  327. function hasNewModelSelectButtons() {
  328. return getNewModelSelectButtons().length > 0;
  329. }
  330. function isConversationStarted() {
  331. return !getModelSelectButton();
  332. }
  333. function setPureConversation() {
  334. const conversation = getConversation();
  335. if (!conversation)
  336. return;
  337. const firstChild = conversation.firstChild;
  338. if (!firstChild)
  339. return;
  340. const newDiv = document.createElement("div");
  341. conversation.insertBefore(newDiv, firstChild.nextSibling);
  342. }
  343. function isHorizontalConversation() {
  344. const conversation = getConversation();
  345. if (!conversation)
  346. return true;
  347. if (!isConversationStarted())
  348. return true;
  349. return conversation.classList.contains("grid");
  350. }
  351. function setHorizontalConversation() {
  352. if (isHorizontalConversation())
  353. return;
  354. setPureConversation();
  355. const conversation = getConversation();
  356. if (!conversation)
  357. return;
  358. conversation.classList.remove("flex", "flex-col", "items-center");
  359. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  360. }
  361. function getShareChatButton() {
  362. return document.querySelector('button[aria-label="Share chat"]');
  363. }
  364. function getCopyLinkButton() {
  365. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  366. var _a;
  367. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  368. })[0];
  369. }
  370.  
  371. // ../../packages/chatkit/dist/chunk-GUZZYTGI.mjs
  372. var bing_exports = {};
  373. __export(bing_exports, {
  374. getActionBar: () => getActionBar,
  375. getChatTurns: () => getChatTurns,
  376. getConversation: () => getConversation2,
  377. getLastChatTurn: () => getLastChatTurn,
  378. getLastResponse: () => getLastResponse2,
  379. getLastResponseText: () => getLastResponseText,
  380. getNewChatButton: () => getNewChatButton,
  381. getRegenerateButton: () => getRegenerateButton2,
  382. getStopGeneratingButton: () => getStopGeneratingButton2,
  383. getSubmitButton: () => getSubmitButton2,
  384. getSuggestionBar: () => getSuggestionBar,
  385. getSuggestionBarButtons: () => getSuggestionBarButtons,
  386. getTextarea: () => getTextarea2,
  387. onSend: () => onSend2,
  388. send: () => send2
  389. });
  390. function getActionBar() {
  391. var _a, _b, _c;
  392. return ((_c = (_b = (_a = document.querySelector("cib-serp")) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelector("cib-action-bar")) == null ? void 0 : _c.shadowRoot) || null;
  393. }
  394. function getSubmitButton2() {
  395. const actionBar = getActionBar();
  396. if (!actionBar) {
  397. return null;
  398. }
  399. return actionBar.querySelector('button[aria-label="Submit"]');
  400. }
  401. function getTextarea2() {
  402. const actionBar = getActionBar();
  403. if (!actionBar) {
  404. return null;
  405. }
  406. return actionBar.querySelector("textarea");
  407. }
  408. function getStopGeneratingButton2() {
  409. var _a, _b;
  410. const actionBar = getActionBar();
  411. if (!actionBar) {
  412. return null;
  413. }
  414. const stopGeneratingButton = (_b = (_a = actionBar.querySelector("cib-typing-indicator")) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelector('button[aria-label="Stop Responding"]');
  415. if (!stopGeneratingButton) {
  416. return null;
  417. }
  418. if (stopGeneratingButton.disabled) {
  419. return null;
  420. }
  421. return stopGeneratingButton;
  422. }
  423. function getNewChatButton() {
  424. const actionBar = getActionBar();
  425. if (!actionBar) {
  426. return null;
  427. }
  428. return actionBar.querySelector('button[aria-label="New topic"]');
  429. }
  430. function getConversation2() {
  431. var _a, _b, _c;
  432. return ((_c = (_b = (_a = document.querySelector("cib-serp")) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelector("cib-conversation")) == null ? void 0 : _c.shadowRoot) || null;
  433. }
  434. function getChatTurns() {
  435. const conversation = getConversation2();
  436. if (!conversation) {
  437. return null;
  438. }
  439. return Array.from(conversation.querySelectorAll("cib-chat-turn")).map((t) => t.shadowRoot);
  440. }
  441. function getSuggestionBar() {
  442. var _a;
  443. const conversation = getConversation2();
  444. if (!conversation) {
  445. return null;
  446. }
  447. return ((_a = conversation.querySelector("cib-suggestion-bar")) == null ? void 0 : _a.shadowRoot) || null;
  448. }
  449. function getSuggestionBarButtons() {
  450. const suggestionBar = getSuggestionBar();
  451. if (!suggestionBar) {
  452. return [];
  453. }
  454. const suggestionItems = Array.from(suggestionBar.querySelectorAll("cib-suggestion-item"));
  455. return suggestionItems.map((i) => {
  456. var _a;
  457. return (_a = i.shadowRoot) == null ? void 0 : _a.querySelector("button");
  458. });
  459. }
  460. function getRegenerateButton2() {
  461. const suggestionBarButtons = getSuggestionBarButtons();
  462. if (!suggestionBarButtons.length) {
  463. return null;
  464. }
  465. return suggestionBarButtons[0];
  466. }
  467. function getLastChatTurn() {
  468. const chatTurns = getChatTurns();
  469. if (!chatTurns) {
  470. return null;
  471. }
  472. return chatTurns[chatTurns.length - 1];
  473. }
  474. function getLastResponse2() {
  475. var _a;
  476. const lastChatTurn = getLastChatTurn();
  477. if (!lastChatTurn) {
  478. return null;
  479. }
  480. return ((_a = lastChatTurn.querySelectorAll("cib-message-group")[1]) == null ? void 0 : _a.shadowRoot) || null;
  481. }
  482. function getLastResponseText() {
  483. var _a;
  484. const lastResponse = getLastResponse2();
  485. if (!lastResponse) {
  486. return null;
  487. }
  488. const message = Array.from(lastResponse.querySelectorAll("cib-message")).map((m) => m.shadowRoot).find((m) => m == null ? void 0 : m.querySelector("cib-shared"));
  489. return ((_a = message == null ? void 0 : message.textContent) == null ? void 0 : _a.trim()) || null;
  490. }
  491. function send2(text) {
  492. const textarea = getTextarea2();
  493. if (!textarea) {
  494. return;
  495. }
  496. textarea.value = text;
  497. textarea.dispatchEvent(new Event("input"));
  498. const submitButton = getSubmitButton2();
  499. if (!submitButton) {
  500. return;
  501. }
  502. submitButton.click();
  503. }
  504. function onSend2(callback) {
  505. const textarea = getTextarea2();
  506. if (!textarea)
  507. return;
  508. textarea.addEventListener("keydown", function(event) {
  509. if (event.key === "Enter" && !event.shiftKey) {
  510. callback();
  511. }
  512. });
  513. const sendButton = getSubmitButton2();
  514. if (!sendButton)
  515. return;
  516. sendButton.addEventListener("mousedown", callback);
  517. }
  518.  
  519. // ../../packages/chatkit/dist/chunk-IIKLOTF4.mjs
  520. var bard_exports = {};
  521. __export(bard_exports, {
  522. getInputArea: () => getInputArea,
  523. getLastPrompt: () => getLastPrompt,
  524. getLatestPromptText: () => getLatestPromptText,
  525. getRegenerateButton: () => getRegenerateButton3,
  526. getResponseElementHTMLs: () => getResponseElementHTMLs2,
  527. getSparkleResting: () => getSparkleResting,
  528. getSparkleThinking: () => getSparkleThinking,
  529. getSubmitButton: () => getSubmitButton3,
  530. getTextarea: () => getTextarea3,
  531. isGenerating: () => isGenerating2,
  532. onSend: () => onSend3,
  533. send: () => send3,
  534. setPromptListener: () => setPromptListener2,
  535. setTextarea: () => setTextarea2
  536. });
  537. function getSparkleResting() {
  538. return document.querySelector("img[src*=sparkle_resting]");
  539. }
  540. function getSparkleThinking() {
  541. return document.querySelector("img[src*=sparkle_thinking]");
  542. }
  543. function getSubmitButton3() {
  544. return document.querySelector('button[aria-label="Send message"]');
  545. }
  546. function getInputArea() {
  547. return document.querySelector(".input-area");
  548. }
  549. function getTextarea3() {
  550. const inputArea = getInputArea();
  551. return inputArea ? inputArea.querySelector(".textarea") : null;
  552. }
  553. function setTextarea2(message) {
  554. const textarea = getTextarea3();
  555. if (!textarea)
  556. return;
  557. textarea.textContent = message;
  558. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  559. }
  560. function getRegenerateButton3() {
  561. return document.querySelector('button[aria-label="Retry"]');
  562. }
  563. function getResponseElementHTMLs2() {
  564. return Array.from(document.querySelectorAll(".model-response-text .markdown")).map((m) => m.innerHTML);
  565. }
  566. function getLastPrompt() {
  567. const promptElements = document.querySelectorAll(".query-text");
  568. const lastPrompt = promptElements[promptElements.length - 1];
  569. return lastPrompt;
  570. }
  571. function getLatestPromptText() {
  572. const lastPrompt = getLastPrompt();
  573. if (!lastPrompt)
  574. return "";
  575. const lastPromptText = lastPrompt.textContent;
  576. return lastPromptText || "";
  577. }
  578. function isGenerating2() {
  579. return getSparkleThinking() !== null;
  580. }
  581. function send3(message) {
  582. return __async(this, null, function* () {
  583. var _a;
  584. setTextarea2(message);
  585. const textarea = getTextarea3();
  586. if (!textarea)
  587. return;
  588. while (textarea.textContent === message) {
  589. yield new Promise((resolve) => setTimeout(resolve, 100));
  590. (_a = getSubmitButton3()) == null ? void 0 : _a.click();
  591. }
  592. for (let i = 0; i < 10; i++) {
  593. if (isGenerating2()) {
  594. return;
  595. }
  596. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  597. }
  598. });
  599. }
  600. function onSend3(callback) {
  601. const textarea = getTextarea3();
  602. if (!textarea)
  603. return;
  604. textarea.addEventListener("keydown", function(event) {
  605. if (event.key === "Enter" && !event.shiftKey) {
  606. callback();
  607. }
  608. });
  609. const sendButton = getSubmitButton3();
  610. if (!sendButton)
  611. return;
  612. sendButton.addEventListener("mousedown", callback);
  613. }
  614. function setPromptListener2(key = "prompt_texts") {
  615. let last_trigger_time = +/* @__PURE__ */ new Date();
  616. if (location.href.includes("bard.google")) {
  617. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  618. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  619. return;
  620. }
  621. last_trigger_time = +/* @__PURE__ */ new Date();
  622. setTimeout(() => __async(this, null, function* () {
  623. const prompt_texts = new_value;
  624. const isLong = prompt_texts.length > 60;
  625. if (prompt_texts.length > 0) {
  626. let firstTime = true;
  627. while (prompt_texts.length > 0) {
  628. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  629. if (!firstTime) {
  630. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  631. }
  632. if (!firstTime && isGenerating2()) {
  633. continue;
  634. }
  635. firstTime = false;
  636. yield send3(prompt_texts.shift() || "");
  637. }
  638. }
  639. }), 0);
  640. GM_setValue(key, []);
  641. }));
  642. }
  643. }
  644.  
  645. // src/index.js
  646. (function() {
  647. "use strict";
  648. const default_menu_all = {};
  649. const menu_all = GM_getValue("menu_all", default_menu_all);
  650. const menus = [
  651. { checker: () => location.href.includes("chat.openai"), name: "openai", value: true },
  652. { checker: () => location.href.includes("bard.google"), name: "bard", value: true },
  653. { checker: () => location.href.includes("Bing+AI"), name: "bing", value: true }
  654. ];
  655. menus.forEach((menu) => {
  656. $(() => menu.checker() && GM_setValue(menu.name, true));
  657. if (GM_getValue(menu.name) == true) {
  658. default_menu_all[menu.name] = menu.value;
  659. }
  660. });
  661. for (let name in default_menu_all) {
  662. if (!(name in menu_all)) {
  663. menu_all[name] = default_menu_all[name];
  664. }
  665. }
  666. const menu_id = GM_getValue("menu_id", {});
  667. function registerMenuCommand(name, value) {
  668. const menuText = ` ${name}\uFF1A${value ? "\u2705" : "\u274C"}`;
  669. const commandCallback = () => {
  670. menu_all[name] = !menu_all[name];
  671. GM_setValue("menu_all", menu_all);
  672. update_menu();
  673. location.reload();
  674. };
  675. return GM_registerMenuCommand(menuText, commandCallback);
  676. }
  677. function update_menu() {
  678. for (let name in menu_all) {
  679. const value = menu_all[name];
  680. if (menu_id[name]) {
  681. GM_unregisterMenuCommand(menu_id[name]);
  682. }
  683. menu_id[name] = registerMenuCommand(name, value);
  684. }
  685. GM_setValue("menu_id", menu_id);
  686. }
  687. update_menu();
  688. let chatgpt_last_prompt = "";
  689. $(() => {
  690. if (menu_all.openai && location.href.includes("chat.openai")) {
  691. chatgpt_exports.onSend(() => {
  692. const textarea = chatgpt_exports.getTextarea();
  693. if (!textarea) {
  694. return;
  695. }
  696. const prompt = textarea.value;
  697. chatgpt_last_prompt = prompt;
  698. GM_setValue("bard_prompt_texts", [prompt]);
  699. GM_setValue("bing_prompt_texts", [prompt]);
  700. });
  701. }
  702. });
  703. let last_trigger_time = +/* @__PURE__ */ new Date();
  704. $(() => {
  705. if (location.href.includes("chat.openai")) {
  706. GM_addValueChangeListener("chatgpt_prompt_texts", (name, old_value, new_value) => {
  707. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  708. return;
  709. }
  710. last_trigger_time = +/* @__PURE__ */ new Date();
  711. setTimeout(() => __async(this, null, function* () {
  712. const prompt_texts = new_value;
  713. if (prompt_texts.length > 0) {
  714. let firstTime = true;
  715. while (prompt_texts.length > 0) {
  716. if (!firstTime) {
  717. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  718. }
  719. if (!firstTime && chatgpt_exports.getRegenerateButton() == void 0) {
  720. continue;
  721. }
  722. firstTime = false;
  723. const prompt_text = prompt_texts.shift();
  724. if (prompt_text === chatgpt_last_prompt) {
  725. continue;
  726. }
  727. chatgpt_exports.send(prompt_text);
  728. }
  729. }
  730. }), 0);
  731. GM_setValue("chatgpt_prompt_texts", []);
  732. });
  733. }
  734. });
  735. let bard_last_prompt = "";
  736. $(() => __async(this, null, function* () {
  737. if (menu_all.bard && location.href.includes("bard.google")) {
  738. while (!bard_exports.getSubmitButton()) {
  739. yield new Promise((resolve) => setTimeout(resolve, 500));
  740. }
  741. bard_exports.onSend(() => {
  742. const textarea = bard_exports.getTextarea();
  743. if (!textarea) {
  744. return;
  745. }
  746. let prompt = textarea.value;
  747. if (!prompt) {
  748. prompt = bard_exports.getLatestPromptText();
  749. }
  750. bard_last_prompt = prompt;
  751. GM_setValue("chatgpt_prompt_texts", [prompt]);
  752. GM_setValue("bing_prompt_texts", [prompt]);
  753. });
  754. }
  755. }));
  756. let lastTriggerTime = +/* @__PURE__ */ new Date();
  757. if (location.href.includes("bard.google")) {
  758. GM_addValueChangeListener("bard_prompt_texts", (name, old_value, new_value) => {
  759. if (+/* @__PURE__ */ new Date() - lastTriggerTime < 500) {
  760. return;
  761. }
  762. lastTriggerTime = +/* @__PURE__ */ new Date();
  763. setTimeout(() => __async(this, null, function* () {
  764. const promptTexts = new_value;
  765. if (promptTexts.length > 0) {
  766. let firstTime = true;
  767. while (promptTexts.length > 0) {
  768. if (!firstTime) {
  769. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  770. }
  771. if (!firstTime && bard_exports.getRegenerateButton() == void 0) {
  772. continue;
  773. }
  774. firstTime = false;
  775. const promptText = promptTexts.shift();
  776. if (promptText === bard_last_prompt) {
  777. continue;
  778. }
  779. bard_exports.send(promptText);
  780. }
  781. }
  782. }), 0);
  783. GM_setValue("bard_prompt_texts", []);
  784. });
  785. }
  786. let bing_last_prompt = "";
  787. $(() => __async(this, null, function* () {
  788. if (menu_all.bing && location.href.includes("Bing+AI")) {
  789. while (!bing_exports.getSubmitButton()) {
  790. yield new Promise((resolve) => setTimeout(resolve, 500));
  791. }
  792. bing_exports.onSend(() => {
  793. const textarea = bing_exports.getTextarea();
  794. if (!textarea) {
  795. return;
  796. }
  797. const prompt = textarea.value;
  798. bing_last_prompt = prompt;
  799. GM_setValue("chatgpt_prompt_texts", [prompt]);
  800. GM_setValue("bard_prompt_texts", [prompt]);
  801. });
  802. }
  803. }));
  804. let last_trigger_time_bing = +/* @__PURE__ */ new Date();
  805. if (location.href.includes("Bing+AI")) {
  806. GM_addValueChangeListener("bing_prompt_texts", (name, old_value, new_value) => {
  807. if (+/* @__PURE__ */ new Date() - last_trigger_time_bing < 500) {
  808. return;
  809. }
  810. last_trigger_time_bing = +/* @__PURE__ */ new Date();
  811. setTimeout(() => __async(this, null, function* () {
  812. const prompt_texts = new_value;
  813. if (prompt_texts.length > 0) {
  814. let firstTime = true;
  815. while (prompt_texts.length > 0) {
  816. if (!firstTime) {
  817. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  818. }
  819. if (!firstTime && bing_exports.getStopGeneratingButton() != void 0) {
  820. continue;
  821. }
  822. firstTime = false;
  823. const prompt_text = prompt_texts.shift();
  824. if (prompt_text === bing_last_prompt) {
  825. continue;
  826. }
  827. bing_exports.send(prompt_text);
  828. }
  829. }
  830. }), 0);
  831. GM_setValue("bing_prompt_texts", []);
  832. });
  833. }
  834. })();
  835. })();