聊天章鱼

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

目前为 2023-07-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name chat-octopus
  3. // @namespace https://github.com/mefengl
  4. // @version 0.2.20
  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-WHDI4UMN.mjs
  72. var chatgpt_exports = {};
  73. __export(chatgpt_exports, {
  74. getContinueGeneratingButton: () => getContinueGeneratingButton,
  75. getConversation: () => getConversation,
  76. getHistoryBlockTitle: () => getHistoryBlockTitle,
  77. getHistoryBlocks: () => getHistoryBlocks,
  78. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  79. getLastResponse: () => getLastResponse,
  80. getLastResponseElement: () => getLastResponseElement,
  81. getModelSelectButton: () => getModelSelectButton,
  82. getNav: () => getNav,
  83. getNewModelSelectButtons: () => getNewModelSelectButtons,
  84. getRegenerateButton: () => getRegenerateButton,
  85. getStopGeneratingButton: () => getStopGeneratingButton,
  86. getSubmitButton: () => getSubmitButton,
  87. getTextarea: () => getTextarea,
  88. getTextareaValue: () => getTextareaValue,
  89. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  90. isConversationStarted: () => isConversationStarted,
  91. isGenerating: () => isGenerating,
  92. isHorizontalConversation: () => isHorizontalConversation,
  93. onSend: () => onSend,
  94. regenerate: () => regenerate,
  95. send: () => send,
  96. setHorizontalConversation: () => setHorizontalConversation,
  97. setPromptListener: () => setPromptListener,
  98. setPureConversation: () => setPureConversation,
  99. setTextarea: () => setTextarea,
  100. waitForIdle: () => waitForIdle
  101. });
  102. function getNav() {
  103. return document.querySelector("nav");
  104. }
  105. function getHistoryBlocks() {
  106. const nav = getNav();
  107. if (!nav)
  108. return [];
  109. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  110. return result;
  111. }
  112. function getHistoryBlockTitle(historyBlock) {
  113. var _a;
  114. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  115. }
  116. function getHistoryBlocksWithTitle() {
  117. const historyBlocks = getHistoryBlocks();
  118. const result = historyBlocks.map((historyBlock) => ({
  119. block: historyBlock,
  120. title: getHistoryBlockTitle(historyBlock)
  121. }));
  122. return result;
  123. }
  124. function getTextarea() {
  125. const form = document.querySelector("form");
  126. if (!form)
  127. return;
  128. const textareas = form.querySelectorAll("textarea");
  129. const result = textareas[0];
  130. return result;
  131. }
  132. function getSubmitButton() {
  133. const textarea = getTextarea();
  134. if (!textarea)
  135. return;
  136. return textarea.nextElementSibling;
  137. }
  138. function getRegenerateButton() {
  139. const form = document.querySelector("form");
  140. if (!form)
  141. return;
  142. const buttons = form.querySelectorAll("button");
  143. const result = Array.from(buttons).find((button) => {
  144. var _a;
  145. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("regenerate");
  146. });
  147. return result;
  148. }
  149. function getContinueGeneratingButton() {
  150. const form = document.querySelector("form");
  151. if (!form)
  152. return;
  153. const buttons = form.querySelectorAll("button");
  154. const result = Array.from(buttons).find((button) => {
  155. var _a;
  156. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("continue generating");
  157. });
  158. return result;
  159. }
  160. function getStopGeneratingButton() {
  161. const form = document.querySelector("form");
  162. if (!form)
  163. return;
  164. const buttons = form.querySelectorAll("button");
  165. const result = Array.from(buttons).find((button) => {
  166. var _a;
  167. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("stop generating");
  168. });
  169. return result;
  170. }
  171. function getLastResponseElement() {
  172. const responseElements = document.querySelectorAll(".group.w-full");
  173. return responseElements[responseElements.length - 1];
  174. }
  175. function getLastResponse() {
  176. const lastResponseElement = getLastResponseElement();
  177. if (!lastResponseElement)
  178. return;
  179. const lastResponse = lastResponseElement.textContent;
  180. return lastResponse;
  181. }
  182. function getTextareaValue() {
  183. var _a;
  184. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  185. }
  186. function setTextarea(message) {
  187. const textarea = getTextarea();
  188. if (!textarea)
  189. return;
  190. textarea.value = message;
  191. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  192. }
  193. function send(message) {
  194. return __async(this, null, function* () {
  195. setTextarea(message);
  196. const textarea = getTextarea();
  197. if (!textarea)
  198. return;
  199. while (textarea.value === message) {
  200. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  201. yield new Promise((resolve) => setTimeout(resolve, 100));
  202. }
  203. });
  204. }
  205. function regenerate() {
  206. const regenerateButton = getRegenerateButton();
  207. if (!regenerateButton)
  208. return;
  209. regenerateButton.click();
  210. }
  211. function onSend(callback) {
  212. const textarea = getTextarea();
  213. if (!textarea)
  214. return;
  215. textarea.addEventListener("keydown", function(event) {
  216. if (event.key === "Enter" && !event.shiftKey) {
  217. callback();
  218. }
  219. });
  220. const sendButton = getSubmitButton();
  221. if (!sendButton)
  222. return;
  223. sendButton.addEventListener("mousedown", callback);
  224. }
  225. function isGenerating() {
  226. var _a, _b;
  227. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  228. }
  229. function waitForIdle() {
  230. return new Promise((resolve) => {
  231. const interval = setInterval(() => {
  232. if (!isGenerating()) {
  233. clearInterval(interval);
  234. resolve();
  235. }
  236. }, 1e3);
  237. });
  238. }
  239. function setPromptListener(key = "prompt_texts") {
  240. let last_trigger_time = +/* @__PURE__ */ new Date();
  241. if (location.href.includes("chat.openai")) {
  242. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  243. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  244. return;
  245. }
  246. last_trigger_time = +/* @__PURE__ */ new Date();
  247. setTimeout(() => __async(this, null, function* () {
  248. var _a;
  249. const prompt_texts = new_value;
  250. const isLong = prompt_texts.length > 60;
  251. if (prompt_texts.length > 0) {
  252. let firstTime = true;
  253. while (prompt_texts.length > 0) {
  254. const waitTime = isLong && !document.hasFocus() ? 30 * 1e3 : 2e3;
  255. if (!firstTime) {
  256. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  257. }
  258. if (!firstTime && isGenerating()) {
  259. continue;
  260. } else if (getContinueGeneratingButton()) {
  261. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  262. continue;
  263. }
  264. firstTime = false;
  265. yield send(prompt_texts.shift() || "");
  266. }
  267. }
  268. }), 0);
  269. GM_setValue(key, []);
  270. }));
  271. }
  272. }
  273. function getConversation() {
  274. var _a, _b;
  275. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  276. }
  277. function getModelSelectButton() {
  278. const conversation = getConversation();
  279. if (!conversation)
  280. return;
  281. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  282. var _a;
  283. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  284. });
  285. }
  286. function getNewModelSelectButtons() {
  287. return Array.from(document.querySelectorAll("[class^='group/button']"));
  288. }
  289. function hasNewModelSelectButtons() {
  290. return getNewModelSelectButtons().length > 0;
  291. }
  292. function isConversationStarted() {
  293. return !getModelSelectButton();
  294. }
  295. function setPureConversation() {
  296. const conversation = getConversation();
  297. if (!conversation)
  298. return;
  299. const firstChild = conversation.firstChild;
  300. if (!firstChild)
  301. return;
  302. const newDiv = document.createElement("div");
  303. conversation.insertBefore(newDiv, firstChild.nextSibling);
  304. }
  305. function isHorizontalConversation() {
  306. const conversation = getConversation();
  307. if (!conversation)
  308. return true;
  309. if (!isConversationStarted())
  310. return true;
  311. return conversation.classList.contains("grid");
  312. }
  313. function setHorizontalConversation() {
  314. if (isHorizontalConversation())
  315. return;
  316. setPureConversation();
  317. const conversation = getConversation();
  318. if (!conversation)
  319. return;
  320. conversation.classList.remove("flex", "flex-col", "items-center");
  321. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  322. }
  323.  
  324. // ../../packages/chatkit/dist/chunk-GUZZYTGI.mjs
  325. var bing_exports = {};
  326. __export(bing_exports, {
  327. getActionBar: () => getActionBar,
  328. getChatTurns: () => getChatTurns,
  329. getConversation: () => getConversation2,
  330. getLastChatTurn: () => getLastChatTurn,
  331. getLastResponse: () => getLastResponse2,
  332. getLastResponseText: () => getLastResponseText,
  333. getNewChatButton: () => getNewChatButton,
  334. getRegenerateButton: () => getRegenerateButton2,
  335. getStopGeneratingButton: () => getStopGeneratingButton2,
  336. getSubmitButton: () => getSubmitButton2,
  337. getSuggestionBar: () => getSuggestionBar,
  338. getSuggestionBarButtons: () => getSuggestionBarButtons,
  339. getTextarea: () => getTextarea2,
  340. onSend: () => onSend2,
  341. send: () => send2
  342. });
  343. function getActionBar() {
  344. var _a, _b, _c;
  345. 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;
  346. }
  347. function getSubmitButton2() {
  348. const actionBar = getActionBar();
  349. if (!actionBar) {
  350. return null;
  351. }
  352. return actionBar.querySelector('button[aria-label="Submit"]');
  353. }
  354. function getTextarea2() {
  355. const actionBar = getActionBar();
  356. if (!actionBar) {
  357. return null;
  358. }
  359. return actionBar.querySelector("textarea");
  360. }
  361. function getStopGeneratingButton2() {
  362. var _a, _b;
  363. const actionBar = getActionBar();
  364. if (!actionBar) {
  365. return null;
  366. }
  367. const stopGeneratingButton = (_b = (_a = actionBar.querySelector("cib-typing-indicator")) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelector('button[aria-label="Stop Responding"]');
  368. if (!stopGeneratingButton) {
  369. return null;
  370. }
  371. if (stopGeneratingButton.disabled) {
  372. return null;
  373. }
  374. return stopGeneratingButton;
  375. }
  376. function getNewChatButton() {
  377. const actionBar = getActionBar();
  378. if (!actionBar) {
  379. return null;
  380. }
  381. return actionBar.querySelector('button[aria-label="New topic"]');
  382. }
  383. function getConversation2() {
  384. var _a, _b, _c;
  385. 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;
  386. }
  387. function getChatTurns() {
  388. const conversation = getConversation2();
  389. if (!conversation) {
  390. return null;
  391. }
  392. return Array.from(conversation.querySelectorAll("cib-chat-turn")).map((t) => t.shadowRoot);
  393. }
  394. function getSuggestionBar() {
  395. var _a;
  396. const conversation = getConversation2();
  397. if (!conversation) {
  398. return null;
  399. }
  400. return ((_a = conversation.querySelector("cib-suggestion-bar")) == null ? void 0 : _a.shadowRoot) || null;
  401. }
  402. function getSuggestionBarButtons() {
  403. const suggestionBar = getSuggestionBar();
  404. if (!suggestionBar) {
  405. return [];
  406. }
  407. const suggestionItems = Array.from(suggestionBar.querySelectorAll("cib-suggestion-item"));
  408. return suggestionItems.map((i) => {
  409. var _a;
  410. return (_a = i.shadowRoot) == null ? void 0 : _a.querySelector("button");
  411. });
  412. }
  413. function getRegenerateButton2() {
  414. const suggestionBarButtons = getSuggestionBarButtons();
  415. if (!suggestionBarButtons.length) {
  416. return null;
  417. }
  418. return suggestionBarButtons[0];
  419. }
  420. function getLastChatTurn() {
  421. const chatTurns = getChatTurns();
  422. if (!chatTurns) {
  423. return null;
  424. }
  425. return chatTurns[chatTurns.length - 1];
  426. }
  427. function getLastResponse2() {
  428. var _a;
  429. const lastChatTurn = getLastChatTurn();
  430. if (!lastChatTurn) {
  431. return null;
  432. }
  433. return ((_a = lastChatTurn.querySelectorAll("cib-message-group")[1]) == null ? void 0 : _a.shadowRoot) || null;
  434. }
  435. function getLastResponseText() {
  436. var _a;
  437. const lastResponse = getLastResponse2();
  438. if (!lastResponse) {
  439. return null;
  440. }
  441. const message = Array.from(lastResponse.querySelectorAll("cib-message")).map((m) => m.shadowRoot).find((m) => m == null ? void 0 : m.querySelector("cib-shared"));
  442. return ((_a = message == null ? void 0 : message.textContent) == null ? void 0 : _a.trim()) || null;
  443. }
  444. function send2(text) {
  445. const textarea = getTextarea2();
  446. if (!textarea) {
  447. return;
  448. }
  449. textarea.value = text;
  450. textarea.dispatchEvent(new Event("input"));
  451. const submitButton = getSubmitButton2();
  452. if (!submitButton) {
  453. return;
  454. }
  455. submitButton.click();
  456. }
  457. function onSend2(callback) {
  458. const textarea = getTextarea2();
  459. if (!textarea)
  460. return;
  461. textarea.addEventListener("keydown", function(event) {
  462. if (event.key === "Enter" && !event.shiftKey) {
  463. callback();
  464. }
  465. });
  466. const sendButton = getSubmitButton2();
  467. if (!sendButton)
  468. return;
  469. sendButton.addEventListener("mousedown", callback);
  470. }
  471.  
  472. // ../../packages/chatkit/dist/chunk-Q66VHVYQ.mjs
  473. var bard_exports = {};
  474. __export(bard_exports, {
  475. getInputArea: () => getInputArea,
  476. getLastPrompt: () => getLastPrompt,
  477. getLatestPromptText: () => getLatestPromptText,
  478. getRegenerateButton: () => getRegenerateButton3,
  479. getSubmitButton: () => getSubmitButton3,
  480. getTextarea: () => getTextarea3,
  481. onSend: () => onSend3,
  482. send: () => send3
  483. });
  484. function getSubmitButton3() {
  485. return document.querySelector('button[aria-label="Send message"]');
  486. }
  487. function getInputArea() {
  488. return document.querySelector(".input-area");
  489. }
  490. function getTextarea3() {
  491. const inputArea = getInputArea();
  492. return inputArea ? inputArea.querySelector("textarea") : null;
  493. }
  494. function getRegenerateButton3() {
  495. return document.querySelector('button[aria-label="Retry"]');
  496. }
  497. function getLastPrompt() {
  498. const promptElements = document.querySelectorAll(".query-text");
  499. const lastPrompt = promptElements[promptElements.length - 1];
  500. return lastPrompt;
  501. }
  502. function getLatestPromptText() {
  503. const lastPrompt = getLastPrompt();
  504. if (!lastPrompt)
  505. return "";
  506. const lastPromptText = lastPrompt.textContent;
  507. return lastPromptText || "";
  508. }
  509. function send3(text) {
  510. const textarea = getTextarea3();
  511. if (!textarea)
  512. return;
  513. textarea.value = text;
  514. textarea.dispatchEvent(new Event("input"));
  515. const submitButton = getSubmitButton3();
  516. if (!submitButton)
  517. return;
  518. submitButton.click();
  519. }
  520. function onSend3(callback) {
  521. const textarea = getTextarea3();
  522. if (!textarea)
  523. return;
  524. textarea.addEventListener("keydown", function(event) {
  525. if (event.key === "Enter" && !event.shiftKey) {
  526. callback();
  527. }
  528. });
  529. const sendButton = getSubmitButton3();
  530. if (!sendButton)
  531. return;
  532. sendButton.addEventListener("mousedown", callback);
  533. }
  534.  
  535. // src/index.js
  536. (function() {
  537. "use strict";
  538. const default_menu_all = {};
  539. const menu_all = GM_getValue("menu_all", default_menu_all);
  540. const menus = [
  541. { checker: () => location.href.includes("chat.openai"), name: "openai", value: true },
  542. { checker: () => location.href.includes("bard.google"), name: "bard", value: true },
  543. { checker: () => location.href.includes("Bing+AI"), name: "bing", value: true }
  544. ];
  545. menus.forEach((menu) => {
  546. $(() => menu.checker() && GM_setValue(menu.name, true));
  547. if (GM_getValue(menu.name) == true) {
  548. default_menu_all[menu.name] = menu.value;
  549. }
  550. });
  551. for (let name in default_menu_all) {
  552. if (!(name in menu_all)) {
  553. menu_all[name] = default_menu_all[name];
  554. }
  555. }
  556. const menu_id = GM_getValue("menu_id", {});
  557. function registerMenuCommand(name, value) {
  558. const menuText = ` ${name}\uFF1A${value ? "\u2705" : "\u274C"}`;
  559. const commandCallback = () => {
  560. menu_all[name] = !menu_all[name];
  561. GM_setValue("menu_all", menu_all);
  562. update_menu();
  563. location.reload();
  564. };
  565. return GM_registerMenuCommand(menuText, commandCallback);
  566. }
  567. function update_menu() {
  568. for (let name in menu_all) {
  569. const value = menu_all[name];
  570. if (menu_id[name]) {
  571. GM_unregisterMenuCommand(menu_id[name]);
  572. }
  573. menu_id[name] = registerMenuCommand(name, value);
  574. }
  575. GM_setValue("menu_id", menu_id);
  576. }
  577. update_menu();
  578. let chatgpt_last_prompt = "";
  579. $(() => {
  580. if (menu_all.openai && location.href.includes("chat.openai")) {
  581. chatgpt_exports.onSend(() => {
  582. const textarea = chatgpt_exports.getTextarea();
  583. if (!textarea) {
  584. return;
  585. }
  586. const prompt = textarea.value;
  587. chatgpt_last_prompt = prompt;
  588. GM_setValue("bard_prompt_texts", [prompt]);
  589. GM_setValue("bing_prompt_texts", [prompt]);
  590. });
  591. }
  592. });
  593. let last_trigger_time = +/* @__PURE__ */ new Date();
  594. $(() => {
  595. if (location.href.includes("chat.openai")) {
  596. GM_addValueChangeListener("chatgpt_prompt_texts", (name, old_value, new_value) => {
  597. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  598. return;
  599. }
  600. last_trigger_time = +/* @__PURE__ */ new Date();
  601. setTimeout(() => __async(this, null, function* () {
  602. const prompt_texts = new_value;
  603. if (prompt_texts.length > 0) {
  604. let firstTime = true;
  605. while (prompt_texts.length > 0) {
  606. if (!firstTime) {
  607. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  608. }
  609. if (!firstTime && chatgpt_exports.getRegenerateButton() == void 0) {
  610. continue;
  611. }
  612. firstTime = false;
  613. const prompt_text = prompt_texts.shift();
  614. if (prompt_text === chatgpt_last_prompt) {
  615. continue;
  616. }
  617. chatgpt_exports.send(prompt_text);
  618. }
  619. }
  620. }), 0);
  621. GM_setValue("chatgpt_prompt_texts", []);
  622. });
  623. }
  624. });
  625. let bard_last_prompt = "";
  626. $(() => __async(this, null, function* () {
  627. if (menu_all.bard && location.href.includes("bard.google")) {
  628. while (!bard_exports.getSubmitButton()) {
  629. yield new Promise((resolve) => setTimeout(resolve, 500));
  630. }
  631. bard_exports.onSend(() => {
  632. const textarea = bard_exports.getTextarea();
  633. if (!textarea) {
  634. return;
  635. }
  636. let prompt = textarea.value;
  637. if (!prompt) {
  638. prompt = bard_exports.getLatestPromptText();
  639. }
  640. bard_last_prompt = prompt;
  641. GM_setValue("chatgpt_prompt_texts", [prompt]);
  642. GM_setValue("bing_prompt_texts", [prompt]);
  643. });
  644. }
  645. }));
  646. let lastTriggerTime = +/* @__PURE__ */ new Date();
  647. if (location.href.includes("bard.google")) {
  648. GM_addValueChangeListener("bard_prompt_texts", (name, old_value, new_value) => {
  649. if (+/* @__PURE__ */ new Date() - lastTriggerTime < 500) {
  650. return;
  651. }
  652. lastTriggerTime = +/* @__PURE__ */ new Date();
  653. setTimeout(() => __async(this, null, function* () {
  654. const promptTexts = new_value;
  655. if (promptTexts.length > 0) {
  656. let firstTime = true;
  657. while (promptTexts.length > 0) {
  658. if (!firstTime) {
  659. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  660. }
  661. if (!firstTime && bard_exports.getRegenerateButton() == void 0) {
  662. continue;
  663. }
  664. firstTime = false;
  665. const promptText = promptTexts.shift();
  666. if (promptText === bard_last_prompt) {
  667. continue;
  668. }
  669. bard_exports.send(promptText);
  670. }
  671. }
  672. }), 0);
  673. GM_setValue("bard_prompt_texts", []);
  674. });
  675. }
  676. let bing_last_prompt = "";
  677. $(() => __async(this, null, function* () {
  678. if (menu_all.bing && location.href.includes("Bing+AI")) {
  679. while (!bing_exports.getSubmitButton()) {
  680. yield new Promise((resolve) => setTimeout(resolve, 500));
  681. }
  682. bing_exports.onSend(() => {
  683. const textarea = bing_exports.getTextarea();
  684. if (!textarea) {
  685. return;
  686. }
  687. const prompt = textarea.value;
  688. bing_last_prompt = prompt;
  689. GM_setValue("chatgpt_prompt_texts", [prompt]);
  690. GM_setValue("bard_prompt_texts", [prompt]);
  691. });
  692. }
  693. }));
  694. let last_trigger_time_bing = +/* @__PURE__ */ new Date();
  695. if (location.href.includes("Bing+AI")) {
  696. GM_addValueChangeListener("bing_prompt_texts", (name, old_value, new_value) => {
  697. if (+/* @__PURE__ */ new Date() - last_trigger_time_bing < 500) {
  698. return;
  699. }
  700. last_trigger_time_bing = +/* @__PURE__ */ new Date();
  701. setTimeout(() => __async(this, null, function* () {
  702. const prompt_texts = new_value;
  703. if (prompt_texts.length > 0) {
  704. let firstTime = true;
  705. while (prompt_texts.length > 0) {
  706. if (!firstTime) {
  707. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  708. }
  709. if (!firstTime && bing_exports.getStopGeneratingButton() != void 0) {
  710. continue;
  711. }
  712. firstTime = false;
  713. const prompt_text = prompt_texts.shift();
  714. if (prompt_text === bing_last_prompt) {
  715. continue;
  716. }
  717. bing_exports.send(prompt_text);
  718. }
  719. }
  720. }), 0);
  721. GM_setValue("bing_prompt_texts", []);
  722. });
  723. }
  724. })();
  725. })();