聊天章鱼

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

当前为 2024-03-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name chat-octopus
  3. // @namespace https://github.com/mefengl
  4. // @version 0.2.43
  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-XMSCK47Z.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. var _a;
  216. setTextarea(message);
  217. const textarea = getTextarea();
  218. if (!textarea)
  219. return;
  220. (_a = getSubmitButton()) == null ? void 0 : _a.click();
  221. for (let i = 0; i < 10; i++) {
  222. if (isGenerating()) {
  223. break;
  224. }
  225. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  226. }
  227. });
  228. }
  229. function regenerate() {
  230. const regenerateButton = getRegenerateButton();
  231. if (!regenerateButton)
  232. return;
  233. regenerateButton.click();
  234. }
  235. function onSend(callback) {
  236. const textarea = getTextarea();
  237. if (!textarea)
  238. return;
  239. textarea.addEventListener("keydown", function(event) {
  240. if (event.key === "Enter" && !event.shiftKey) {
  241. callback();
  242. }
  243. });
  244. const sendButton = getSubmitButton();
  245. if (!sendButton)
  246. return;
  247. sendButton.addEventListener("mousedown", callback);
  248. }
  249. function isGenerating() {
  250. var _a, _b;
  251. if (getNewStopGeneratingButton()) {
  252. return true;
  253. }
  254. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  255. }
  256. function waitForIdle() {
  257. return new Promise((resolve) => {
  258. const interval = setInterval(() => {
  259. if (!isGenerating()) {
  260. clearInterval(interval);
  261. resolve();
  262. }
  263. }, 1e3);
  264. });
  265. }
  266. function sendArray(messages) {
  267. return __async(this, null, function* () {
  268. var _a, _b;
  269. let firstTime = true;
  270. const isLong = messages.length > 60;
  271. let stop = false;
  272. while (messages.length > 0 || stop) {
  273. stop = false;
  274. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  275. if (!firstTime) {
  276. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  277. }
  278. firstTime = false;
  279. if (isGenerating()) {
  280. continue;
  281. } else if (getContinueGeneratingButton()) {
  282. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  283. stop = true;
  284. continue;
  285. } else if (getRegenerateButton() && !getTextarea()) {
  286. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  287. (_b = getRegenerateButton()) == null ? void 0 : _b.click();
  288. stop = true;
  289. continue;
  290. }
  291. if (messages.length === 0) {
  292. break;
  293. }
  294. yield send(messages.shift() || "");
  295. }
  296. });
  297. }
  298. function setPromptListener(key = "prompt_texts") {
  299. let last_trigger_time = +/* @__PURE__ */ new Date();
  300. if (location.href.includes("chat.openai")) {
  301. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  302. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  303. return;
  304. }
  305. last_trigger_time = +/* @__PURE__ */ new Date();
  306. setTimeout(() => __async(this, null, function* () {
  307. sendArray(new_value);
  308. GM_setValue(key, []);
  309. }), 0);
  310. }));
  311. }
  312. }
  313. function getConversation() {
  314. var _a, _b;
  315. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  316. }
  317. function getModelSelectButton() {
  318. const conversation = getConversation();
  319. if (!conversation)
  320. return;
  321. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  322. var _a;
  323. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  324. });
  325. }
  326. function getNewModelSelectButtons() {
  327. return Array.from(document.querySelectorAll("[class^='group/button']"));
  328. }
  329. function hasNewModelSelectButtons() {
  330. return getNewModelSelectButtons().length > 0;
  331. }
  332. function isConversationStarted() {
  333. return !getModelSelectButton();
  334. }
  335. function setPureConversation() {
  336. const conversation = getConversation();
  337. if (!conversation)
  338. return;
  339. const firstChild = conversation.firstChild;
  340. if (!firstChild)
  341. return;
  342. const newDiv = document.createElement("div");
  343. conversation.insertBefore(newDiv, firstChild.nextSibling);
  344. }
  345. function isHorizontalConversation() {
  346. const conversation = getConversation();
  347. if (!conversation)
  348. return true;
  349. if (!isConversationStarted())
  350. return true;
  351. return conversation.classList.contains("grid");
  352. }
  353. function setHorizontalConversation() {
  354. if (isHorizontalConversation())
  355. return;
  356. setPureConversation();
  357. const conversation = getConversation();
  358. if (!conversation)
  359. return;
  360. conversation.classList.remove("flex", "flex-col", "items-center");
  361. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  362. }
  363. function getShareChatButton() {
  364. return document.querySelector('button[aria-label="Share chat"]');
  365. }
  366. function getCopyLinkButton() {
  367. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  368. var _a;
  369. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  370. })[0];
  371. }
  372.  
  373. // ../../packages/chatkit/dist/chunk-GUZZYTGI.mjs
  374. var bing_exports = {};
  375. __export(bing_exports, {
  376. getActionBar: () => getActionBar,
  377. getChatTurns: () => getChatTurns,
  378. getConversation: () => getConversation2,
  379. getLastChatTurn: () => getLastChatTurn,
  380. getLastResponse: () => getLastResponse2,
  381. getLastResponseText: () => getLastResponseText,
  382. getNewChatButton: () => getNewChatButton,
  383. getRegenerateButton: () => getRegenerateButton2,
  384. getStopGeneratingButton: () => getStopGeneratingButton2,
  385. getSubmitButton: () => getSubmitButton2,
  386. getSuggestionBar: () => getSuggestionBar,
  387. getSuggestionBarButtons: () => getSuggestionBarButtons,
  388. getTextarea: () => getTextarea2,
  389. onSend: () => onSend2,
  390. send: () => send2
  391. });
  392. function getActionBar() {
  393. var _a, _b, _c;
  394. 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;
  395. }
  396. function getSubmitButton2() {
  397. const actionBar = getActionBar();
  398. if (!actionBar) {
  399. return null;
  400. }
  401. return actionBar.querySelector('button[aria-label="Submit"]');
  402. }
  403. function getTextarea2() {
  404. const actionBar = getActionBar();
  405. if (!actionBar) {
  406. return null;
  407. }
  408. return actionBar.querySelector("textarea");
  409. }
  410. function getStopGeneratingButton2() {
  411. var _a, _b;
  412. const actionBar = getActionBar();
  413. if (!actionBar) {
  414. return null;
  415. }
  416. const stopGeneratingButton = (_b = (_a = actionBar.querySelector("cib-typing-indicator")) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelector('button[aria-label="Stop Responding"]');
  417. if (!stopGeneratingButton) {
  418. return null;
  419. }
  420. if (stopGeneratingButton.disabled) {
  421. return null;
  422. }
  423. return stopGeneratingButton;
  424. }
  425. function getNewChatButton() {
  426. const actionBar = getActionBar();
  427. if (!actionBar) {
  428. return null;
  429. }
  430. return actionBar.querySelector('button[aria-label="New topic"]');
  431. }
  432. function getConversation2() {
  433. var _a, _b, _c;
  434. 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;
  435. }
  436. function getChatTurns() {
  437. const conversation = getConversation2();
  438. if (!conversation) {
  439. return null;
  440. }
  441. return Array.from(conversation.querySelectorAll("cib-chat-turn")).map((t) => t.shadowRoot);
  442. }
  443. function getSuggestionBar() {
  444. var _a;
  445. const conversation = getConversation2();
  446. if (!conversation) {
  447. return null;
  448. }
  449. return ((_a = conversation.querySelector("cib-suggestion-bar")) == null ? void 0 : _a.shadowRoot) || null;
  450. }
  451. function getSuggestionBarButtons() {
  452. const suggestionBar = getSuggestionBar();
  453. if (!suggestionBar) {
  454. return [];
  455. }
  456. const suggestionItems = Array.from(suggestionBar.querySelectorAll("cib-suggestion-item"));
  457. return suggestionItems.map((i) => {
  458. var _a;
  459. return (_a = i.shadowRoot) == null ? void 0 : _a.querySelector("button");
  460. });
  461. }
  462. function getRegenerateButton2() {
  463. const suggestionBarButtons = getSuggestionBarButtons();
  464. if (!suggestionBarButtons.length) {
  465. return null;
  466. }
  467. return suggestionBarButtons[0];
  468. }
  469. function getLastChatTurn() {
  470. const chatTurns = getChatTurns();
  471. if (!chatTurns) {
  472. return null;
  473. }
  474. return chatTurns[chatTurns.length - 1];
  475. }
  476. function getLastResponse2() {
  477. var _a;
  478. const lastChatTurn = getLastChatTurn();
  479. if (!lastChatTurn) {
  480. return null;
  481. }
  482. return ((_a = lastChatTurn.querySelectorAll("cib-message-group")[1]) == null ? void 0 : _a.shadowRoot) || null;
  483. }
  484. function getLastResponseText() {
  485. var _a;
  486. const lastResponse = getLastResponse2();
  487. if (!lastResponse) {
  488. return null;
  489. }
  490. const message = Array.from(lastResponse.querySelectorAll("cib-message")).map((m) => m.shadowRoot).find((m) => m == null ? void 0 : m.querySelector("cib-shared"));
  491. return ((_a = message == null ? void 0 : message.textContent) == null ? void 0 : _a.trim()) || null;
  492. }
  493. function send2(text) {
  494. const textarea = getTextarea2();
  495. if (!textarea) {
  496. return;
  497. }
  498. textarea.value = text;
  499. textarea.dispatchEvent(new Event("input"));
  500. const submitButton = getSubmitButton2();
  501. if (!submitButton) {
  502. return;
  503. }
  504. submitButton.click();
  505. }
  506. function onSend2(callback) {
  507. const textarea = getTextarea2();
  508. if (!textarea)
  509. return;
  510. textarea.addEventListener("keydown", function(event) {
  511. if (event.key === "Enter" && !event.shiftKey) {
  512. callback();
  513. }
  514. });
  515. const sendButton = getSubmitButton2();
  516. if (!sendButton)
  517. return;
  518. sendButton.addEventListener("mousedown", callback);
  519. }
  520.  
  521. // ../../packages/chatkit/dist/chunk-IIKLOTF4.mjs
  522. var bard_exports = {};
  523. __export(bard_exports, {
  524. getInputArea: () => getInputArea,
  525. getLastPrompt: () => getLastPrompt,
  526. getLatestPromptText: () => getLatestPromptText,
  527. getRegenerateButton: () => getRegenerateButton3,
  528. getResponseElementHTMLs: () => getResponseElementHTMLs2,
  529. getSparkleResting: () => getSparkleResting,
  530. getSparkleThinking: () => getSparkleThinking,
  531. getSubmitButton: () => getSubmitButton3,
  532. getTextarea: () => getTextarea3,
  533. isGenerating: () => isGenerating2,
  534. onSend: () => onSend3,
  535. send: () => send3,
  536. setPromptListener: () => setPromptListener2,
  537. setTextarea: () => setTextarea2
  538. });
  539. function getSparkleResting() {
  540. return document.querySelector("img[src*=sparkle_resting]");
  541. }
  542. function getSparkleThinking() {
  543. return document.querySelector("img[src*=sparkle_thinking]");
  544. }
  545. function getSubmitButton3() {
  546. return document.querySelector('button[aria-label="Send message"]');
  547. }
  548. function getInputArea() {
  549. return document.querySelector(".input-area");
  550. }
  551. function getTextarea3() {
  552. const inputArea = getInputArea();
  553. return inputArea ? inputArea.querySelector(".textarea") : null;
  554. }
  555. function setTextarea2(message) {
  556. const textarea = getTextarea3();
  557. if (!textarea)
  558. return;
  559. textarea.textContent = message;
  560. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  561. }
  562. function getRegenerateButton3() {
  563. return document.querySelector('button[aria-label="Retry"]');
  564. }
  565. function getResponseElementHTMLs2() {
  566. return Array.from(document.querySelectorAll(".model-response-text .markdown")).map((m) => m.innerHTML);
  567. }
  568. function getLastPrompt() {
  569. const promptElements = document.querySelectorAll(".query-text");
  570. const lastPrompt = promptElements[promptElements.length - 1];
  571. return lastPrompt;
  572. }
  573. function getLatestPromptText() {
  574. const lastPrompt = getLastPrompt();
  575. if (!lastPrompt)
  576. return "";
  577. const lastPromptText = lastPrompt.textContent;
  578. return lastPromptText || "";
  579. }
  580. function isGenerating2() {
  581. return getSparkleThinking() !== null;
  582. }
  583. function send3(message) {
  584. return __async(this, null, function* () {
  585. var _a;
  586. setTextarea2(message);
  587. const textarea = getTextarea3();
  588. if (!textarea)
  589. return;
  590. while (textarea.textContent === message) {
  591. yield new Promise((resolve) => setTimeout(resolve, 100));
  592. (_a = getSubmitButton3()) == null ? void 0 : _a.click();
  593. }
  594. for (let i = 0; i < 10; i++) {
  595. if (isGenerating2()) {
  596. return;
  597. }
  598. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  599. }
  600. });
  601. }
  602. function onSend3(callback) {
  603. const textarea = getTextarea3();
  604. if (!textarea)
  605. return;
  606. textarea.addEventListener("keydown", function(event) {
  607. if (event.key === "Enter" && !event.shiftKey) {
  608. callback();
  609. }
  610. });
  611. const sendButton = getSubmitButton3();
  612. if (!sendButton)
  613. return;
  614. sendButton.addEventListener("mousedown", callback);
  615. }
  616. function setPromptListener2(key = "prompt_texts") {
  617. let last_trigger_time = +/* @__PURE__ */ new Date();
  618. if (location.href.includes("bard.google")) {
  619. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  620. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  621. return;
  622. }
  623. last_trigger_time = +/* @__PURE__ */ new Date();
  624. setTimeout(() => __async(this, null, function* () {
  625. const prompt_texts = new_value;
  626. const isLong = prompt_texts.length > 60;
  627. if (prompt_texts.length > 0) {
  628. let firstTime = true;
  629. while (prompt_texts.length > 0) {
  630. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  631. if (!firstTime) {
  632. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  633. }
  634. if (!firstTime && isGenerating2()) {
  635. continue;
  636. }
  637. firstTime = false;
  638. yield send3(prompt_texts.shift() || "");
  639. }
  640. }
  641. }), 0);
  642. GM_setValue(key, []);
  643. }));
  644. }
  645. }
  646.  
  647. // src/index.js
  648. (function() {
  649. "use strict";
  650. const default_menu_all = {};
  651. const menu_all = GM_getValue("menu_all", default_menu_all);
  652. const menus = [
  653. { checker: () => location.href.includes("chat.openai"), name: "openai", value: true },
  654. { checker: () => location.href.includes("bard.google"), name: "bard", value: true },
  655. { checker: () => location.href.includes("Bing+AI"), name: "bing", value: true }
  656. ];
  657. menus.forEach((menu) => {
  658. $(() => menu.checker() && GM_setValue(menu.name, true));
  659. if (GM_getValue(menu.name) == true) {
  660. default_menu_all[menu.name] = menu.value;
  661. }
  662. });
  663. for (let name in default_menu_all) {
  664. if (!(name in menu_all)) {
  665. menu_all[name] = default_menu_all[name];
  666. }
  667. }
  668. const menu_id = GM_getValue("menu_id", {});
  669. function registerMenuCommand(name, value) {
  670. const menuText = ` ${name}\uFF1A${value ? "\u2705" : "\u274C"}`;
  671. const commandCallback = () => {
  672. menu_all[name] = !menu_all[name];
  673. GM_setValue("menu_all", menu_all);
  674. update_menu();
  675. location.reload();
  676. };
  677. return GM_registerMenuCommand(menuText, commandCallback);
  678. }
  679. function update_menu() {
  680. for (let name in menu_all) {
  681. const value = menu_all[name];
  682. if (menu_id[name]) {
  683. GM_unregisterMenuCommand(menu_id[name]);
  684. }
  685. menu_id[name] = registerMenuCommand(name, value);
  686. }
  687. GM_setValue("menu_id", menu_id);
  688. }
  689. update_menu();
  690. let chatgpt_last_prompt = "";
  691. $(() => {
  692. if (menu_all.openai && location.href.includes("chat.openai")) {
  693. chatgpt_exports.onSend(() => {
  694. const textarea = chatgpt_exports.getTextarea();
  695. if (!textarea) {
  696. return;
  697. }
  698. const prompt = textarea.value;
  699. chatgpt_last_prompt = prompt;
  700. GM_setValue("bard_prompt_texts", [prompt]);
  701. GM_setValue("bing_prompt_texts", [prompt]);
  702. });
  703. }
  704. });
  705. let last_trigger_time = +/* @__PURE__ */ new Date();
  706. $(() => {
  707. if (location.href.includes("chat.openai")) {
  708. GM_addValueChangeListener("chatgpt_prompt_texts", (name, old_value, new_value) => {
  709. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  710. return;
  711. }
  712. last_trigger_time = +/* @__PURE__ */ new Date();
  713. setTimeout(() => __async(this, null, function* () {
  714. const prompt_texts = new_value;
  715. if (prompt_texts.length > 0) {
  716. let firstTime = true;
  717. while (prompt_texts.length > 0) {
  718. if (!firstTime) {
  719. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  720. }
  721. if (!firstTime && chatgpt_exports.getRegenerateButton() == void 0) {
  722. continue;
  723. }
  724. firstTime = false;
  725. const prompt_text = prompt_texts.shift();
  726. if (prompt_text === chatgpt_last_prompt) {
  727. continue;
  728. }
  729. chatgpt_exports.send(prompt_text);
  730. }
  731. }
  732. }), 0);
  733. GM_setValue("chatgpt_prompt_texts", []);
  734. });
  735. }
  736. });
  737. let bard_last_prompt = "";
  738. $(() => __async(this, null, function* () {
  739. if (menu_all.bard && location.href.includes("bard.google")) {
  740. while (!bard_exports.getSubmitButton()) {
  741. yield new Promise((resolve) => setTimeout(resolve, 500));
  742. }
  743. bard_exports.onSend(() => {
  744. const textarea = bard_exports.getTextarea();
  745. if (!textarea) {
  746. return;
  747. }
  748. let prompt = textarea.value;
  749. if (!prompt) {
  750. prompt = bard_exports.getLatestPromptText();
  751. }
  752. bard_last_prompt = prompt;
  753. GM_setValue("chatgpt_prompt_texts", [prompt]);
  754. GM_setValue("bing_prompt_texts", [prompt]);
  755. });
  756. }
  757. }));
  758. let lastTriggerTime = +/* @__PURE__ */ new Date();
  759. if (location.href.includes("bard.google")) {
  760. GM_addValueChangeListener("bard_prompt_texts", (name, old_value, new_value) => {
  761. if (+/* @__PURE__ */ new Date() - lastTriggerTime < 500) {
  762. return;
  763. }
  764. lastTriggerTime = +/* @__PURE__ */ new Date();
  765. setTimeout(() => __async(this, null, function* () {
  766. const promptTexts = new_value;
  767. if (promptTexts.length > 0) {
  768. let firstTime = true;
  769. while (promptTexts.length > 0) {
  770. if (!firstTime) {
  771. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  772. }
  773. if (!firstTime && bard_exports.getRegenerateButton() == void 0) {
  774. continue;
  775. }
  776. firstTime = false;
  777. const promptText = promptTexts.shift();
  778. if (promptText === bard_last_prompt) {
  779. continue;
  780. }
  781. bard_exports.send(promptText);
  782. }
  783. }
  784. }), 0);
  785. GM_setValue("bard_prompt_texts", []);
  786. });
  787. }
  788. let bing_last_prompt = "";
  789. $(() => __async(this, null, function* () {
  790. if (menu_all.bing && location.href.includes("Bing+AI")) {
  791. while (!bing_exports.getSubmitButton()) {
  792. yield new Promise((resolve) => setTimeout(resolve, 500));
  793. }
  794. bing_exports.onSend(() => {
  795. const textarea = bing_exports.getTextarea();
  796. if (!textarea) {
  797. return;
  798. }
  799. const prompt = textarea.value;
  800. bing_last_prompt = prompt;
  801. GM_setValue("chatgpt_prompt_texts", [prompt]);
  802. GM_setValue("bard_prompt_texts", [prompt]);
  803. });
  804. }
  805. }));
  806. let last_trigger_time_bing = +/* @__PURE__ */ new Date();
  807. if (location.href.includes("Bing+AI")) {
  808. GM_addValueChangeListener("bing_prompt_texts", (name, old_value, new_value) => {
  809. if (+/* @__PURE__ */ new Date() - last_trigger_time_bing < 500) {
  810. return;
  811. }
  812. last_trigger_time_bing = +/* @__PURE__ */ new Date();
  813. setTimeout(() => __async(this, null, function* () {
  814. const prompt_texts = new_value;
  815. if (prompt_texts.length > 0) {
  816. let firstTime = true;
  817. while (prompt_texts.length > 0) {
  818. if (!firstTime) {
  819. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  820. }
  821. if (!firstTime && bing_exports.getStopGeneratingButton() != void 0) {
  822. continue;
  823. }
  824. firstTime = false;
  825. const prompt_text = prompt_texts.shift();
  826. if (prompt_text === bing_last_prompt) {
  827. continue;
  828. }
  829. bing_exports.send(prompt_text);
  830. }
  831. }
  832. }), 0);
  833. GM_setValue("bing_prompt_texts", []);
  834. });
  835. }
  836. })();
  837. })();