Doozy

A wonderful day spent with ChatGPT

بۇ قوليازمىنى قاچىلاش؟
ئاپتورنىڭ تەۋسىيەلىگەن قوليازمىسى

سىز بەلكىم ChatGPT Auto-Continue 🔄 نى ياقتۇرۇشىڭىز مۇمكىن.

بۇ قوليازمىنى قاچىلاش
  1. // ==UserScript==
  2. // @name Doozy
  3. // @namespace https://github.com/mefengl
  4. // @version 0.8.31
  5. // @description A wonderful day spent with ChatGPT
  6. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  7. // @author mefengl
  8. // @match https://chatgpt.com/*
  9. // @match http://*/*
  10. // @match https://*/*
  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 Doozy
  21. // @description:en A wonderful day spent with ChatGPT
  22. // @name:zh-CN 奇妙的一天
  23. // @description:zh-CN 与ChatGPT度过的美好时光
  24. // @name:es Doozy
  25. // @description:es Un día maravilloso pasado con ChatGPT
  26. // @name:hi धमाकेदार
  27. // @description:hi चैट जीपीटी के साथ बिताए एक अद्भुत दिन
  28. // @name:ar دوزي
  29. // @description:ar يوم رائع قضيته مع ChatGPT
  30. // @name:pt Espetacular
  31. // @description:pt Um dia maravilhoso passado com o ChatGPT
  32. // @name:ru Блестящий
  33. // @description:ru Замечательный день, проведенный с ChatGPT
  34. // @name:ja ドゥーズィ
  35. // @description:ja ChatGPTと過ごす素晴らしい一日
  36. // @name:de Doozy
  37. // @description:de Ein wunderbarer Tag mit ChatGPT verbracht
  38. // @name:fr Doozy
  39. // @description:fr Une journée merveilleuse passée avec ChatGPT
  40. // ==/UserScript==
  41. "use strict";
  42. (() => {
  43. var __create = Object.create;
  44. var __defProp = Object.defineProperty;
  45. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  46. var __getOwnPropNames = Object.getOwnPropertyNames;
  47. var __getProtoOf = Object.getPrototypeOf;
  48. var __hasOwnProp = Object.prototype.hasOwnProperty;
  49. var __commonJS = (cb, mod) => function __require() {
  50. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  51. };
  52. var __copyProps = (to, from, except, desc) => {
  53. if (from && typeof from === "object" || typeof from === "function") {
  54. for (let key of __getOwnPropNames(from))
  55. if (!__hasOwnProp.call(to, key) && key !== except)
  56. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  57. }
  58. return to;
  59. };
  60. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  61. // If the importer is in node compatibility mode or this is not an ESM
  62. // file that has been converted to a CommonJS file using a Babel-
  63. // compatible transform (i.e. "__esModule" has not been set), then set
  64. // "default" to the CommonJS "module.exports" for node compatibility.
  65. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  66. mod
  67. ));
  68. var __async = (__this, __arguments, generator) => {
  69. return new Promise((resolve, reject) => {
  70. var fulfilled = (value) => {
  71. try {
  72. step(generator.next(value));
  73. } catch (e) {
  74. reject(e);
  75. }
  76. };
  77. var rejected = (value) => {
  78. try {
  79. step(generator.throw(value));
  80. } catch (e) {
  81. reject(e);
  82. }
  83. };
  84. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  85. step((generator = generator.apply(__this, __arguments)).next());
  86. });
  87. };
  88.  
  89. // ../../packages/chatkit/dist/chatgpt/index.js
  90. var require_chatgpt = __commonJS({
  91. "../../packages/chatkit/dist/chatgpt/index.js"(exports, module) {
  92. "use strict";
  93. var __defProp2 = Object.defineProperty;
  94. var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
  95. var __getOwnPropNames2 = Object.getOwnPropertyNames;
  96. var __hasOwnProp2 = Object.prototype.hasOwnProperty;
  97. var __export = (target, all) => {
  98. for (var name in all)
  99. __defProp2(target, name, { get: all[name], enumerable: true });
  100. };
  101. var __copyProps2 = (to, from, except, desc) => {
  102. if (from && typeof from === "object" || typeof from === "function") {
  103. for (let key of __getOwnPropNames2(from))
  104. if (!__hasOwnProp2.call(to, key) && key !== except)
  105. __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
  106. }
  107. return to;
  108. };
  109. var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
  110. var chatgpt_exports = {};
  111. __export(chatgpt_exports, {
  112. clickFollowUpButton: () => clickFollowUpButton,
  113. getButton: () => getButton,
  114. getContinueGeneratingButton: () => getContinueGeneratingButton,
  115. getConversation: () => getConversation,
  116. getCopyLinkButton: () => getCopyLinkButton,
  117. getFollowUpButtons: () => getFollowUpButtons,
  118. getHistoryBlockTitle: () => getHistoryBlockTitle,
  119. getHistoryBlocks: () => getHistoryBlocks,
  120. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  121. getInitialButtons: () => getInitialButtons,
  122. getLastResponse: () => getLastResponse,
  123. getLastResponseElement: () => getLastResponseElement,
  124. getModelSelectButton: () => getModelSelectButton,
  125. getNav: () => getNav,
  126. getNewModelSelectButtons: () => getNewModelSelectButtons,
  127. getRegenerateButton: () => getRegenerateButton2,
  128. getResponseElementHTMLs: () => getResponseElementHTMLs,
  129. getShareChatButton: () => getShareChatButton,
  130. getStopGeneratingButton: () => getStopGeneratingButton,
  131. getSubmitButton: () => getSubmitButton,
  132. getTextarea: () => getTextarea,
  133. getTextareaValue: () => getTextareaValue,
  134. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  135. isConversationStarted: () => isConversationStarted,
  136. isGenerating: () => isGenerating,
  137. isHorizontalConversation: () => isHorizontalConversation,
  138. onSend: () => onSend,
  139. regenerate: () => regenerate,
  140. send: () => send2,
  141. sendArray: () => sendArray,
  142. setHorizontalConversation: () => setHorizontalConversation,
  143. setPromptListener: () => setPromptListener,
  144. setPureConversation: () => setPureConversation,
  145. setTextarea: () => setTextarea,
  146. waitForIdle: () => waitForIdle
  147. });
  148. module.exports = __toCommonJS(chatgpt_exports);
  149. function getNav() {
  150. return document.querySelector("nav");
  151. }
  152. function getHistoryBlocks() {
  153. const nav = getNav();
  154. if (!nav)
  155. return [];
  156. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  157. return result;
  158. }
  159. function getHistoryBlockTitle(historyBlock) {
  160. var _a;
  161. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  162. }
  163. function getHistoryBlocksWithTitle() {
  164. const historyBlocks = getHistoryBlocks();
  165. const result = historyBlocks.map((historyBlock) => ({
  166. block: historyBlock,
  167. title: getHistoryBlockTitle(historyBlock)
  168. }));
  169. return result;
  170. }
  171. function getTextarea() {
  172. const form = document.querySelector("form");
  173. if (!form)
  174. return;
  175. const textareas = form.querySelectorAll("textarea");
  176. const result = textareas[0];
  177. return result;
  178. }
  179. function getNewSubmitButton() {
  180. return document.querySelector('button[data-testid$="send-button"]');
  181. }
  182. function getSubmitButton() {
  183. if (getNewSubmitButton()) {
  184. return getNewSubmitButton();
  185. }
  186. const textarea = getTextarea();
  187. if (!textarea)
  188. return;
  189. return textarea.nextElementSibling;
  190. }
  191. function getInitialButtons() {
  192. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => button.querySelectorAll(".truncate").length === 2);
  193. }
  194. function getFollowUpButtons() {
  195. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  196. var _a;
  197. return (_a = button.textContent) == null ? void 0 : _a.trim().match(/[.!?]$/);
  198. });
  199. }
  200. function clickFollowUpButton(index) {
  201. const followUpButtons = getFollowUpButtons();
  202. if (followUpButtons.length === 0)
  203. return;
  204. if (index === void 0 || index < 0 || index >= followUpButtons.length) {
  205. index = Math.floor(Math.random() * followUpButtons.length);
  206. }
  207. followUpButtons[index].click();
  208. }
  209. function getButton(text) {
  210. const button = Array.from(document.querySelectorAll('button[data-testid$="button"]')).find((button2) => {
  211. var _a;
  212. return (_a = button2.getAttribute("data-testid")) == null ? void 0 : _a.includes(text);
  213. });
  214. if (button)
  215. return button;
  216. return Array.from(document.querySelectorAll('button[as="button"]')).find((button2) => {
  217. var _a;
  218. return (_a = button2.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  219. });
  220. }
  221. function getRegenerateButton2() {
  222. return getButton("regenerate");
  223. }
  224. function getContinueGeneratingButton() {
  225. const buttonInWideScreen = getButton("continue");
  226. if (buttonInWideScreen)
  227. return buttonInWideScreen;
  228. function getNthGenerationDescendants(element, generation) {
  229. const descendants = [];
  230. function findDescendants(node, currentDepth) {
  231. if (currentDepth === generation) {
  232. descendants.push(node);
  233. return;
  234. }
  235. node.childNodes.forEach((child) => findDescendants(child, currentDepth + 1));
  236. }
  237. findDescendants(element, 0);
  238. return descendants;
  239. }
  240. const form = document.querySelector("form");
  241. if (!form)
  242. return;
  243. const seventhGenerationDescendants = getNthGenerationDescendants(form, 7);
  244. if (seventhGenerationDescendants.length === 0 || seventhGenerationDescendants[0].nodeName !== "BUTTON")
  245. return;
  246. return seventhGenerationDescendants[0];
  247. }
  248. function getNewStopGeneratingButton() {
  249. const stopButtonNotLogin = document.querySelector('button[aria-label="Stop generating"]');
  250. const stopButton = document.querySelector('button[data-testid$="stop-button"]');
  251. return stopButtonNotLogin || stopButton;
  252. }
  253. function getStopGeneratingButton() {
  254. return getNewStopGeneratingButton() || getButton("stop");
  255. }
  256. function getResponseElementHTMLs() {
  257. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  258. }
  259. function getLastResponseElement() {
  260. const responseElements = document.querySelectorAll(".group.w-full");
  261. return responseElements[responseElements.length - 1];
  262. }
  263. function getLastResponse() {
  264. const lastResponseElement = getLastResponseElement();
  265. if (!lastResponseElement)
  266. return;
  267. const lastResponse = lastResponseElement.textContent;
  268. return lastResponse;
  269. }
  270. function getTextareaValue() {
  271. var _a;
  272. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  273. }
  274. function setTextarea(message) {
  275. const textarea = getTextarea();
  276. if (!textarea)
  277. return;
  278. textarea.value = message;
  279. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  280. }
  281. function send2(message) {
  282. return __async(this, null, function* () {
  283. var _a;
  284. setTextarea(message);
  285. const textarea = getTextarea();
  286. if (!textarea)
  287. return;
  288. (_a = getSubmitButton()) == null ? void 0 : _a.click();
  289. for (let i = 0; i < 10; i++) {
  290. if (isGenerating()) {
  291. break;
  292. }
  293. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  294. }
  295. });
  296. }
  297. function regenerate() {
  298. const regenerateButton = getRegenerateButton2();
  299. if (!regenerateButton)
  300. return;
  301. regenerateButton.click();
  302. }
  303. function onSend(callback) {
  304. const textarea = getTextarea();
  305. if (!textarea)
  306. return;
  307. textarea.addEventListener("keydown", function(event) {
  308. if (event.key === "Enter" && !event.shiftKey) {
  309. callback();
  310. }
  311. });
  312. const sendButton = getSubmitButton();
  313. if (!sendButton)
  314. return;
  315. sendButton.addEventListener("mousedown", callback);
  316. }
  317. function isGenerating() {
  318. var _a, _b;
  319. if (getNewStopGeneratingButton()) {
  320. return true;
  321. }
  322. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  323. }
  324. function waitForIdle() {
  325. return new Promise((resolve) => {
  326. const interval = setInterval(() => {
  327. if (!isGenerating()) {
  328. clearInterval(interval);
  329. resolve();
  330. }
  331. }, 1e3);
  332. });
  333. }
  334. function sendArray(messages) {
  335. return __async(this, null, function* () {
  336. var _a, _b;
  337. let firstTime = true;
  338. const isLong = messages.length > 60;
  339. let stop = false;
  340. while (messages.length > 0 || stop) {
  341. stop = false;
  342. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  343. if (!firstTime) {
  344. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  345. }
  346. firstTime = false;
  347. if (isGenerating()) {
  348. continue;
  349. } else if (getContinueGeneratingButton()) {
  350. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  351. stop = true;
  352. continue;
  353. } else if (getRegenerateButton2() && !getTextarea()) {
  354. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  355. (_b = getRegenerateButton2()) == null ? void 0 : _b.click();
  356. stop = true;
  357. continue;
  358. }
  359. if (messages.length === 0) {
  360. break;
  361. }
  362. yield send2(messages.shift() || "");
  363. }
  364. });
  365. }
  366. function setPromptListener(key = "prompt_texts") {
  367. let last_trigger_time = +/* @__PURE__ */ new Date();
  368. if (location.href.includes("chatgpt.com")) {
  369. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  370. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  371. return;
  372. }
  373. last_trigger_time = +/* @__PURE__ */ new Date();
  374. setTimeout(() => __async(this, null, function* () {
  375. sendArray(new_value);
  376. GM_setValue(key, []);
  377. }), 0);
  378. }));
  379. }
  380. }
  381. function getConversation() {
  382. var _a, _b;
  383. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  384. }
  385. function getModelSelectButton() {
  386. const conversation = getConversation();
  387. if (!conversation)
  388. return;
  389. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  390. var _a;
  391. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  392. });
  393. }
  394. function getNewModelSelectButtons() {
  395. return Array.from(document.querySelectorAll("[class^='group/button']"));
  396. }
  397. function hasNewModelSelectButtons() {
  398. return getNewModelSelectButtons().length > 0;
  399. }
  400. function isConversationStarted() {
  401. return !getModelSelectButton();
  402. }
  403. function setPureConversation() {
  404. const conversation = getConversation();
  405. if (!conversation)
  406. return;
  407. const firstChild = conversation.firstChild;
  408. if (!firstChild)
  409. return;
  410. const newDiv = document.createElement("div");
  411. conversation.insertBefore(newDiv, firstChild.nextSibling);
  412. }
  413. function isHorizontalConversation() {
  414. const conversation = getConversation();
  415. if (!conversation)
  416. return true;
  417. if (!isConversationStarted())
  418. return true;
  419. return conversation.classList.contains("grid");
  420. }
  421. function setHorizontalConversation() {
  422. if (isHorizontalConversation())
  423. return;
  424. setPureConversation();
  425. const conversation = getConversation();
  426. if (!conversation)
  427. return;
  428. conversation.classList.remove("flex", "flex-col", "items-center");
  429. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  430. }
  431. function getShareChatButton() {
  432. return document.querySelector('button[aria-label="Share chat"]');
  433. }
  434. function getCopyLinkButton() {
  435. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  436. var _a;
  437. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  438. })[0];
  439. }
  440. }
  441. });
  442.  
  443. // ../../packages/chatkit/chatgpt.js
  444. var require_chatgpt2 = __commonJS({
  445. "../../packages/chatkit/chatgpt.js"(exports, module) {
  446. module.exports = require_chatgpt();
  447. }
  448. });
  449.  
  450. // src/index.js
  451. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  452. (function() {
  453. "use strict";
  454. const default_menu_all = {};
  455. const menu_all = GM_getValue("menu_all", default_menu_all);
  456. const menus = [
  457. { checker: () => location.href.includes("book.douban"), name: "douban_book", value: true },
  458. { checker: () => location.href.includes("zhihu"), name: "zhihu", value: true },
  459. { checker: () => location.href.includes("news.ycombinator"), name: "hackernews", value: true },
  460. { checker: () => location.href.includes("github"), name: "github", value: true },
  461. { checker: () => location.href.includes("wikipedia"), name: "wikipedia", value: true },
  462. { checker: () => location.href.includes("nytimes.com"), name: "nytimes", value: true },
  463. { checker: () => location.href.includes("baidu.com"), name: "baidu", value: true },
  464. { checker: () => location.href.includes("reddit.com"), name: "reddit", value: true },
  465. { checker: () => location.href.includes("google.com"), name: "google", value: true },
  466. { checker: () => location.href.includes("youtube.com"), name: "youtube", value: true }
  467. ];
  468. menus.forEach((menu) => {
  469. $(() => menu.checker() && GM_setValue(menu.name, true) && console.log(`\u5F00\u542F ${menu.name} \u83DC\u5355`));
  470. if (GM_getValue(menu.name) == true) {
  471. default_menu_all[menu.name] = menu.value;
  472. }
  473. });
  474. for (let name in default_menu_all) {
  475. if (!(name in menu_all)) {
  476. menu_all[name] = default_menu_all[name];
  477. }
  478. }
  479. const menu_id = GM_getValue("menu_id", {});
  480. function registerMenuCommand(name, value) {
  481. const menuText = ` ${name}\uFF1A${value ? "\u2705" : "\u274C"}`;
  482. const commandCallback = () => {
  483. menu_all[name] = !menu_all[name];
  484. GM_setValue("menu_all", menu_all);
  485. update_menu();
  486. location.reload();
  487. };
  488. return GM_registerMenuCommand(menuText, commandCallback);
  489. }
  490. function update_menu() {
  491. for (let name in menu_all) {
  492. const value = menu_all[name];
  493. if (menu_id[name]) {
  494. GM_unregisterMenuCommand(menu_id[name]);
  495. }
  496. menu_id[name] = registerMenuCommand(name, value);
  497. }
  498. GM_setValue("menu_id", menu_id);
  499. }
  500. update_menu();
  501. const douban_book_prompts = [
  502. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u7684\u4E3B\u8981\u89C2\u70B9\u5217\u6210\u8868\u683C\u4F1A\u662F\uFF1A`,
  503. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u6BD4\u8F83\u91CD\u8981\u7684\u7AE0\u8282\u4F1A\u662F\uFF1A`,
  504. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u5728\u54EA\u4E9B\u65B9\u9762\u662F\u6709\u4E89\u8BAE\u7684\u4F1A\u662F\uFF1A`,
  505. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u5F53\u4EBA\u4EEC\u751F\u6D3B\u5728\u4E0D\u540C\u7684\u65F6\u4EE3\u65F6\uFF0C\u4F1A\u6709\u4EC0\u4E48\u4E0D\u540C\u7684\u89C2\u70B9\u4F1A\u662F\uFF1A`,
  506. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u7EFC\u5408Goodreads\u8BC4\u5206\u548C\u8C46\u74E3\u7B49\u5404\u79CD\u8BC4\u5206\u548C\u8BC4\u4EF7\u4F1A\u662F\uFF1A`,
  507. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u7684\u7C7B\u4F3C\u4E66\u7C4D\u6216\u6587\u7AE0\u548C\u5B83\u4EEC\u7684\u533A\u522B\u4F1A\u662F\uFF1A`,
  508. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u7684\u89C2\u70B9\u76F8\u53CD\u7684\u4E66\u7C4D\u6216\u6587\u7AE0\u548C\u5BF9\u5E94\u7684\u89C2\u70B9\u4F1A\u662F\uFF1A`
  509. ];
  510. const question_prompts = [
  511. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u6697\u542B\u7684\u89C2\u70B9\u662F\uFF1A`,
  512. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u5E94\u8BE5\u53BB\u53CD\u601D\uFF1A`,
  513. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u60F3\u8981\u6539\u8FDB\u6216\u89E3\u51B3\u5B83\uFF0C\u53EF\u4EE5\u4ECE\u8FD9\u4E9B\u65B9\u9762\u5165\u624B\uFF1A`,
  514. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u63D0\u95EE\u8005\u548C\u63D0\u95EE\u8005\u7684\u76EE\u7684\u662F\uFF1A`,
  515. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u95EE\u9898\u7684\u76F8\u5173\u5386\u53F2\u662F\uFF1A`,
  516. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u4E0D\u540C\u7684\u56FD\u5BB6\u5BF9\u8FD9\u4E2A\u95EE\u9898\u7684\u770B\u6CD5\u4F1A\u662F\uFF1A`,
  517. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u7C7B\u4F3C\u95EE\u9898\u548C\u5B83\u4EEC\u7684\u533A\u522B\u4F1A\u662F\uFF1A`,
  518. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u89C2\u70B9\u76F8\u53CD\u7684\u95EE\u9898\u548C\u5BF9\u5E94\u7684\u89C2\u70B9\u4F1A\u662F\uFF1A`,
  519. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u5E7D\u9ED8\u7684\u56DE\u7B54\u4F1A\u662F\uFF1A`,
  520. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u4E3B\u8981\u89C2\u70B9\u5217\u6210\u8868\u683C\u4F1A\u662F\uFF1A`,
  521. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u76F8\u5173\u4E66\u7C4D\u3001\u6587\u7AE0\u3001\u89C6\u9891\u6216\u7F51\u7AD9\u4F1A\u662F\uFF1A`,
  522. ({ question }) => `\u4ECE\u8FD9\u4E2A\u95EE\u9898\uFF1A${question}\uFF0C\u53EF\u4EE5\u5F15\u7533\u51FA\u8FD9\u4E9B\u95EE\u9898\uFF1A`
  523. ];
  524. const github_prompts = [
  525. ({ website }) => `${website}\u7684\u6700\u4F73\u5B9E\u8DF5\u662F\uFF1A`,
  526. ({ website }) => `${website}\u7684\u7C7B\u4F3C\u9879\u76EE\u662F\uFF1A`,
  527. ({ website }) => `${website}\u7684\u76F8\u5173\u4E66\u7C4D\u3001\u6587\u7AE0\u3001\u89C6\u9891\u6216\u7F51\u7AD9\u662F\uFF1A`
  528. ];
  529. function chatgpt_trigger(prompt_prepare, prompts) {
  530. const prepare_data = prompt_prepare();
  531. const prompt_texts = prompts.map((prompt) => prompt(prepare_data));
  532. GM_setValue("prompt_texts", prompt_texts);
  533. }
  534. const triggers = [
  535. {
  536. checker: () => menu_all.douban_book && location.href.includes("book.douban.com/subject"),
  537. prepare: () => {
  538. const title = $("meta[property='og:title']").attr("content");
  539. const author = $("meta[property='book:author']").attr("content");
  540. return { title, author };
  541. },
  542. prompts: douban_book_prompts
  543. },
  544. {
  545. checker: () => menu_all.zhihu && location.href.includes("zhihu.com/question"),
  546. prepare: () => {
  547. const question = $('meta[itemprop="name"]').attr("content");
  548. return { question };
  549. },
  550. prompts: [...question_prompts]
  551. },
  552. {
  553. checker: () => menu_all.hackernews && location.href.includes("news.ycombinator.com/item"),
  554. prepare: () => {
  555. const question = $("td.title > span.titleline > a").text();
  556. return { question };
  557. },
  558. prompts: [...question_prompts]
  559. },
  560. {
  561. checker: () => menu_all.github && location.href.includes("github.com"),
  562. prepare: () => {
  563. const parts = location.href.split("/");
  564. if (parts.length >= 5 && parts[parts.length - 2] && parts[parts.length - 1]) {
  565. const website = parts[parts.length - 2] + "/" + parts[parts.length - 1];
  566. return { website };
  567. }
  568. },
  569. prompts: github_prompts
  570. },
  571. {
  572. checker: () => menu_all.wikipedia && location.href.includes("wikipedia.org/wiki/"),
  573. prepare: () => {
  574. const title = $("h1#firstHeading").text();
  575. const summary = $("div.mw-parser-output p").first().text();
  576. return { title, summary };
  577. },
  578. prompts: [
  579. ({ title }) => `${title}\u7684\u5386\u53F2\u548C\u91CD\u8981\u4E8B\u4EF6\u6709\u54EA\u4E9B\uFF1F`,
  580. ({ title }) => `${title}\u4E0E\u5176\u4ED6\u76F8\u5173\u4E3B\u9898\u7684\u6BD4\u8F83\u548C\u5BF9\u6BD4\u4F1A\u662F\uFF1A`,
  581. ({ title }) => `${title}\u7684\u4E3B\u8981\u89C2\u70B9\u5217\u6210\u8868\u683C\u4F1A\u662F\uFF1A`,
  582. ({ title }) => `${title}\u7684\u5173\u952E\u6982\u5FF5\u548C\u672F\u8BED\u662F\u4EC0\u4E48\uFF1F`,
  583. ({ title }) => `${title}\u7684\u7C7B\u4F3C\u8BCD\u6761\u6216\u76F8\u5173\u7814\u7A76\u548C\u5B83\u4EEC\u7684\u533A\u522B\u4F1A\u662F\uFF1A`
  584. ]
  585. },
  586. {
  587. checker: () => menu_all.nytimes && location.href.includes("nytimes.com"),
  588. prepare: () => {
  589. const articleTitle = $("h1").text();
  590. return { question: articleTitle };
  591. },
  592. prompts: [...question_prompts]
  593. },
  594. {
  595. checker: () => menu_all.baidu && location.href.includes("www.baidu.com/s"),
  596. prepare: () => {
  597. const keyword = $("input#kw").val();
  598. return { keyword };
  599. },
  600. prompts: [
  601. ({ keyword }) => `\u5173\u4E8E"${keyword}"\u7684\u6700\u65B0\u65B0\u95FB\u6709\u54EA\u4E9B\uFF1F`,
  602. ({ keyword }) => `"${keyword}"\u7684\u5B9A\u4E49\u548C\u89E3\u91CA\u662F\u4EC0\u4E48\uFF1F`,
  603. ({ keyword }) => `\u5BF9\u4E8E"${keyword}"\u8FD9\u4E2A\u8BDD\u9898\uFF0C\u4F60\u6709\u4EC0\u4E48\u89C2\u70B9\u6216\u770B\u6CD5\uFF1F`,
  604. ({ keyword }) => `\u8DDF"${keyword}"\u76F8\u5173\u7684\u4EBA\u7269\u6216\u4E8B\u4EF6\u6709\u54EA\u4E9B\uFF1F`,
  605. ({ keyword }) => `\u6700\u8FD1\u8DDF"${keyword}"\u76F8\u5173\u7684\u70ED\u95E8\u8BDD\u9898\u662F\u4EC0\u4E48\uFF1F`
  606. ]
  607. },
  608. {
  609. checker: () => menu_all.reddit && location.href.includes("reddit.com"),
  610. prepare: () => {
  611. const postTitle = $("h1._eYtD2XCVieq6emjKBH3m").text();
  612. const postContent = $("div._3W_31WoaKsKsZfNldTiz5M").first().text();
  613. return { postTitle, postContent };
  614. },
  615. prompts: [
  616. ({ postTitle }) => `\u5173\u4E8E"${postTitle}"\uFF0C\u4F60\u6709\u4EC0\u4E48\u60F3\u6CD5\u6216\u8BC4\u8BBA\uFF1F`,
  617. ({ postTitle }) => `\u80FD\u7ED9\u5927\u5BB6\u5206\u4EAB\u4E00\u4E9B"${postTitle}"\u7684\u76F8\u5173\u4FE1\u606F\u5417\uFF1F`,
  618. ({ postTitle }) => `\u5728"${postTitle}"\u7684\u8BA8\u8BBA\u4E2D\uFF0C\u6709\u54EA\u4E9B\u89C2\u70B9\u6216\u610F\u89C1\u6700\u503C\u5F97\u5173\u6CE8\uFF1F`,
  619. ({ postTitle }) => `\u5BF9\u4E8E"${postTitle}"\uFF0C\u4F60\u7684\u770B\u6CD5\u662F\u5426\u4E0E\u5176\u4ED6\u4EBA\u4E0D\u540C\uFF1F`,
  620. ({ postTitle }) => `\u8BF7\u7B80\u8981\u4ECB\u7ECD\u4E00\u4E0B"${postTitle}"\u7684\u4E3B\u8981\u5185\u5BB9\u548C\u80CC\u666F\u3002`
  621. ]
  622. },
  623. {
  624. checker: () => menu_all.google && location.href.includes("google.com/search?q="),
  625. prepare: () => {
  626. const keyword = $("input[name='q']").val();
  627. return { keyword };
  628. },
  629. prompts: [
  630. ({ keyword }) => `\u5173\u4E8E"${keyword}"\u7684\u6700\u65B0\u641C\u7D22\u7ED3\u679C\u6709\u54EA\u4E9B\uFF1F`,
  631. ({ keyword }) => `\u5BF9\u4E8E"${keyword}"\u8FD9\u4E2A\u8BDD\u9898\uFF0C\u4F60\u6709\u4EC0\u4E48\u89C2\u70B9\u6216\u770B\u6CD5\uFF1F`,
  632. ({ keyword }) => `\u8DDF"${keyword}"\u76F8\u5173\u7684\u4EBA\u7269\u6216\u4E8B\u4EF6\u6709\u54EA\u4E9B\uFF1F`,
  633. ({ keyword }) => `\u6700\u8FD1\u8DDF"${keyword}"\u76F8\u5173\u7684\u70ED\u95E8\u8BDD\u9898\u662F\u4EC0\u4E48\uFF1F`
  634. ]
  635. },
  636. {
  637. checker: () => menu_all.youtube && location.href.includes("youtube.com/watch"),
  638. prepare: () => {
  639. const metaTitle = $('meta[name="title"]').attr("content");
  640. return { metaTitle };
  641. },
  642. prompts: [
  643. ({ metaTitle }) => `\u5173\u4E8E"${metaTitle}"\u7684\u89C2\u70B9\u6216\u8BC4\u8BBA\u6709\u54EA\u4E9B\uFF1F`,
  644. ({ metaTitle }) => `\u80FD\u7ED9\u5927\u5BB6\u5206\u4EAB\u4E00\u4E9B\u5173\u4E8E"${metaTitle}"\u7684\u76F8\u5173\u4FE1\u606F\u5417\uFF1F`,
  645. ({ metaTitle }) => `\u5728"${metaTitle}"\u7684\u8BA8\u8BBA\u4E2D\uFF0C\u6709\u54EA\u4E9B\u89C2\u70B9\u6216\u610F\u89C1\u6700\u503C\u5F97\u5173\u6CE8\uFF1F`,
  646. ({ metaTitle }) => `\u5BF9\u4E8E"${metaTitle}"\uFF0C\u4F60\u7684\u770B\u6CD5\u662F\u5426\u4E0E\u5176\u4ED6\u4EBA\u4E0D\u540C\uFF1F`,
  647. ({ metaTitle }) => `\u8BF7\u7B80\u8981\u4ECB\u7ECD\u4E00\u4E0B"${metaTitle}"\u7684\u4E3B\u8981\u5185\u5BB9\u548C\u80CC\u666F\u3002`
  648. ]
  649. }
  650. ];
  651. triggers.forEach((trigger) => {
  652. trigger.checker() && chatgpt_trigger(trigger.prepare, trigger.prompts);
  653. });
  654. let last_trigger_time = +/* @__PURE__ */ new Date();
  655. $(() => {
  656. if (location.href.includes("chatgpt.com")) {
  657. GM_addValueChangeListener("prompt_texts", (name, old_value, new_value) => {
  658. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  659. return;
  660. }
  661. last_trigger_time = +/* @__PURE__ */ new Date();
  662. setTimeout(() => __async(this, null, function* () {
  663. const prompt_texts = new_value;
  664. if (prompt_texts.length > 0) {
  665. let firstTime = true;
  666. while (prompt_texts.length > 0) {
  667. if (!firstTime) {
  668. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  669. }
  670. if (!firstTime && (0, import_chatgpt.getRegenerateButton)() == void 0) {
  671. continue;
  672. }
  673. firstTime = false;
  674. const prompt_text = prompt_texts.shift();
  675. (0, import_chatgpt.send)(prompt_text);
  676. }
  677. }
  678. }), 0);
  679. GM_setValue("prompt_texts", []);
  680. });
  681. }
  682. });
  683. })();
  684. })();