聊天章鱼

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

当前为 2023-07-26 提交的版本,查看 最新版本

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