聊天章鱼

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

当前为 2023-10-31 提交的版本,查看 最新版本

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