奇妙的一天

与ChatGPT度过的美好时光

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

  1. // ==UserScript==
  2. // @name Doozy
  3. // @namespace https://github.com/mefengl
  4. // @version 0.8.12
  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://chat.openai.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. getContinueGeneratingButton: () => getContinueGeneratingButton,
  113. getConversation: () => getConversation,
  114. getHistoryBlockTitle: () => getHistoryBlockTitle,
  115. getHistoryBlocks: () => getHistoryBlocks,
  116. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  117. getLastResponse: () => getLastResponse,
  118. getLastResponseElement: () => getLastResponseElement,
  119. getModelSelectButton: () => getModelSelectButton,
  120. getNav: () => getNav,
  121. getNewModelSelectButtons: () => getNewModelSelectButtons,
  122. getRegenerateButton: () => getRegenerateButton2,
  123. getResponseElementHTMLs: () => getResponseElementHTMLs,
  124. getStopGeneratingButton: () => getStopGeneratingButton,
  125. getSubmitButton: () => getSubmitButton,
  126. getTextarea: () => getTextarea,
  127. getTextareaValue: () => getTextareaValue,
  128. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  129. isConversationStarted: () => isConversationStarted,
  130. isGenerating: () => isGenerating,
  131. isHorizontalConversation: () => isHorizontalConversation,
  132. onSend: () => onSend,
  133. regenerate: () => regenerate,
  134. send: () => send2,
  135. setHorizontalConversation: () => setHorizontalConversation,
  136. setPromptListener: () => setPromptListener,
  137. setPureConversation: () => setPureConversation,
  138. setTextarea: () => setTextarea,
  139. waitForIdle: () => waitForIdle
  140. });
  141. module.exports = __toCommonJS(chatgpt_exports);
  142. function getNav() {
  143. return document.querySelector("nav");
  144. }
  145. function getHistoryBlocks() {
  146. const nav = getNav();
  147. if (!nav)
  148. return [];
  149. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  150. return result;
  151. }
  152. function getHistoryBlockTitle(historyBlock) {
  153. var _a;
  154. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  155. }
  156. function getHistoryBlocksWithTitle() {
  157. const historyBlocks = getHistoryBlocks();
  158. const result = historyBlocks.map((historyBlock) => ({
  159. block: historyBlock,
  160. title: getHistoryBlockTitle(historyBlock)
  161. }));
  162. return result;
  163. }
  164. function getTextarea() {
  165. const form = document.querySelector("form");
  166. if (!form)
  167. return;
  168. const textareas = form.querySelectorAll("textarea");
  169. const result = textareas[0];
  170. return result;
  171. }
  172. function getSubmitButton() {
  173. const textarea = getTextarea();
  174. if (!textarea)
  175. return;
  176. return textarea.nextElementSibling;
  177. }
  178. function getRegenerateButton2() {
  179. const form = document.querySelector("form");
  180. if (!form)
  181. return;
  182. const buttons = form.querySelectorAll("button");
  183. const result = Array.from(buttons).find((button) => {
  184. var _a;
  185. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("regenerate");
  186. });
  187. return result;
  188. }
  189. function getContinueGeneratingButton() {
  190. const form = document.querySelector("form");
  191. if (!form)
  192. return;
  193. const buttons = form.querySelectorAll("button");
  194. const result = Array.from(buttons).find((button) => {
  195. var _a;
  196. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("continue generating");
  197. });
  198. return result;
  199. }
  200. function getStopGeneratingButton() {
  201. const form = document.querySelector("form");
  202. if (!form)
  203. return;
  204. const buttons = form.querySelectorAll("button");
  205. const result = Array.from(buttons).find((button) => {
  206. var _a;
  207. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("stop generating");
  208. });
  209. return result;
  210. }
  211. function getResponseElementHTMLs() {
  212. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  213. }
  214. function getLastResponseElement() {
  215. const responseElements = document.querySelectorAll(".group.w-full");
  216. return responseElements[responseElements.length - 1];
  217. }
  218. function getLastResponse() {
  219. const lastResponseElement = getLastResponseElement();
  220. if (!lastResponseElement)
  221. return;
  222. const lastResponse = lastResponseElement.textContent;
  223. return lastResponse;
  224. }
  225. function getTextareaValue() {
  226. var _a;
  227. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  228. }
  229. function setTextarea(message) {
  230. const textarea = getTextarea();
  231. if (!textarea)
  232. return;
  233. textarea.value = message;
  234. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  235. }
  236. function send2(message) {
  237. return __async(this, null, function* () {
  238. setTextarea(message);
  239. const textarea = getTextarea();
  240. if (!textarea)
  241. return;
  242. while (textarea.value === message) {
  243. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  244. yield new Promise((resolve) => setTimeout(resolve, 100));
  245. }
  246. });
  247. }
  248. function regenerate() {
  249. const regenerateButton = getRegenerateButton2();
  250. if (!regenerateButton)
  251. return;
  252. regenerateButton.click();
  253. }
  254. function onSend(callback) {
  255. const textarea = getTextarea();
  256. if (!textarea)
  257. return;
  258. textarea.addEventListener("keydown", function(event) {
  259. if (event.key === "Enter" && !event.shiftKey) {
  260. callback();
  261. }
  262. });
  263. const sendButton = getSubmitButton();
  264. if (!sendButton)
  265. return;
  266. sendButton.addEventListener("mousedown", callback);
  267. }
  268. function isGenerating() {
  269. var _a, _b;
  270. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  271. }
  272. function waitForIdle() {
  273. return new Promise((resolve) => {
  274. const interval = setInterval(() => {
  275. if (!isGenerating()) {
  276. clearInterval(interval);
  277. resolve();
  278. }
  279. }, 1e3);
  280. });
  281. }
  282. function setPromptListener(key = "prompt_texts") {
  283. let last_trigger_time = +/* @__PURE__ */ new Date();
  284. if (location.href.includes("chat.openai")) {
  285. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  286. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  287. return;
  288. }
  289. last_trigger_time = +/* @__PURE__ */ new Date();
  290. setTimeout(() => __async(this, null, function* () {
  291. var _a, _b;
  292. const prompt_texts = new_value;
  293. const isLong = prompt_texts.length > 60;
  294. if (prompt_texts.length > 0) {
  295. let firstTime = true;
  296. while (prompt_texts.length > 0) {
  297. const waitTime = isLong && !document.hasFocus() ? 30 * 1e3 : 2e3;
  298. if (!firstTime) {
  299. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  300. }
  301. if (!firstTime && isGenerating()) {
  302. continue;
  303. } else if (getContinueGeneratingButton()) {
  304. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  305. continue;
  306. } else if (getRegenerateButton2() && !getTextarea()) {
  307. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  308. (_b = getRegenerateButton2()) == null ? void 0 : _b.click();
  309. continue;
  310. }
  311. firstTime = false;
  312. yield send2(prompt_texts.shift() || "");
  313. }
  314. }
  315. }), 0);
  316. GM_setValue(key, []);
  317. }));
  318. }
  319. }
  320. function getConversation() {
  321. var _a, _b;
  322. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  323. }
  324. function getModelSelectButton() {
  325. const conversation = getConversation();
  326. if (!conversation)
  327. return;
  328. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  329. var _a;
  330. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  331. });
  332. }
  333. function getNewModelSelectButtons() {
  334. return Array.from(document.querySelectorAll("[class^='group/button']"));
  335. }
  336. function hasNewModelSelectButtons() {
  337. return getNewModelSelectButtons().length > 0;
  338. }
  339. function isConversationStarted() {
  340. return !getModelSelectButton();
  341. }
  342. function setPureConversation() {
  343. const conversation = getConversation();
  344. if (!conversation)
  345. return;
  346. const firstChild = conversation.firstChild;
  347. if (!firstChild)
  348. return;
  349. const newDiv = document.createElement("div");
  350. conversation.insertBefore(newDiv, firstChild.nextSibling);
  351. }
  352. function isHorizontalConversation() {
  353. const conversation = getConversation();
  354. if (!conversation)
  355. return true;
  356. if (!isConversationStarted())
  357. return true;
  358. return conversation.classList.contains("grid");
  359. }
  360. function setHorizontalConversation() {
  361. if (isHorizontalConversation())
  362. return;
  363. setPureConversation();
  364. const conversation = getConversation();
  365. if (!conversation)
  366. return;
  367. conversation.classList.remove("flex", "flex-col", "items-center");
  368. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  369. }
  370. }
  371. });
  372.  
  373. // ../../packages/chatkit/chatgpt.js
  374. var require_chatgpt2 = __commonJS({
  375. "../../packages/chatkit/chatgpt.js"(exports, module) {
  376. module.exports = require_chatgpt();
  377. }
  378. });
  379.  
  380. // src/index.js
  381. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  382. (function() {
  383. "use strict";
  384. const default_menu_all = {};
  385. const menu_all = GM_getValue("menu_all", default_menu_all);
  386. const menus = [
  387. { checker: () => location.href.includes("book.douban"), name: "douban_book", value: true },
  388. { checker: () => location.href.includes("zhihu"), name: "zhihu", value: true },
  389. { checker: () => location.href.includes("news.ycombinator"), name: "hackernews", value: true },
  390. { checker: () => location.href.includes("github"), name: "github", value: true },
  391. { checker: () => location.href.includes("wikipedia"), name: "wikipedia", value: true },
  392. { checker: () => location.href.includes("nytimes.com"), name: "nytimes", value: true },
  393. { checker: () => location.href.includes("baidu.com"), name: "baidu", value: true },
  394. { checker: () => location.href.includes("reddit.com"), name: "reddit", value: true },
  395. { checker: () => location.href.includes("google.com"), name: "google", value: true },
  396. { checker: () => location.href.includes("youtube.com"), name: "youtube", value: true }
  397. ];
  398. menus.forEach((menu) => {
  399. $(() => menu.checker() && GM_setValue(menu.name, true) && console.log(`\u5F00\u542F ${menu.name} \u83DC\u5355`));
  400. if (GM_getValue(menu.name) == true) {
  401. default_menu_all[menu.name] = menu.value;
  402. }
  403. });
  404. for (let name in default_menu_all) {
  405. if (!(name in menu_all)) {
  406. menu_all[name] = default_menu_all[name];
  407. }
  408. }
  409. const menu_id = GM_getValue("menu_id", {});
  410. function registerMenuCommand(name, value) {
  411. const menuText = ` ${name}\uFF1A${value ? "\u2705" : "\u274C"}`;
  412. const commandCallback = () => {
  413. menu_all[name] = !menu_all[name];
  414. GM_setValue("menu_all", menu_all);
  415. update_menu();
  416. location.reload();
  417. };
  418. return GM_registerMenuCommand(menuText, commandCallback);
  419. }
  420. function update_menu() {
  421. for (let name in menu_all) {
  422. const value = menu_all[name];
  423. if (menu_id[name]) {
  424. GM_unregisterMenuCommand(menu_id[name]);
  425. }
  426. menu_id[name] = registerMenuCommand(name, value);
  427. }
  428. GM_setValue("menu_id", menu_id);
  429. }
  430. update_menu();
  431. const douban_book_prompts = [
  432. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u7684\u4E3B\u8981\u89C2\u70B9\u5217\u6210\u8868\u683C\u4F1A\u662F\uFF1A`,
  433. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u6BD4\u8F83\u91CD\u8981\u7684\u7AE0\u8282\u4F1A\u662F\uFF1A`,
  434. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u5728\u54EA\u4E9B\u65B9\u9762\u662F\u6709\u4E89\u8BAE\u7684\u4F1A\u662F\uFF1A`,
  435. ({ 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`,
  436. ({ 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`,
  437. ({ title, author }) => `${author}\u7684\u300A${title}\u300B\u7684\u7C7B\u4F3C\u4E66\u7C4D\u6216\u6587\u7AE0\u548C\u5B83\u4EEC\u7684\u533A\u522B\u4F1A\u662F\uFF1A`,
  438. ({ 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`
  439. ];
  440. const question_prompts = [
  441. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u6697\u542B\u7684\u89C2\u70B9\u662F\uFF1A`,
  442. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u5E94\u8BE5\u53BB\u53CD\u601D\uFF1A`,
  443. ({ 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`,
  444. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u63D0\u95EE\u8005\u548C\u63D0\u95EE\u8005\u7684\u76EE\u7684\u662F\uFF1A`,
  445. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u95EE\u9898\u7684\u76F8\u5173\u5386\u53F2\u662F\uFF1A`,
  446. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u4E0D\u540C\u7684\u56FD\u5BB6\u5BF9\u8FD9\u4E2A\u95EE\u9898\u7684\u770B\u6CD5\u4F1A\u662F\uFF1A`,
  447. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u7C7B\u4F3C\u95EE\u9898\u548C\u5B83\u4EEC\u7684\u533A\u522B\u4F1A\u662F\uFF1A`,
  448. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u89C2\u70B9\u76F8\u53CD\u7684\u95EE\u9898\u548C\u5BF9\u5E94\u7684\u89C2\u70B9\u4F1A\u662F\uFF1A`,
  449. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u5E7D\u9ED8\u7684\u56DE\u7B54\u4F1A\u662F\uFF1A`,
  450. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u4E3B\u8981\u89C2\u70B9\u5217\u6210\u8868\u683C\u4F1A\u662F\uFF1A`,
  451. ({ question }) => `\u95EE\u9898\uFF1A${question}\uFF0C\u76F8\u5173\u4E66\u7C4D\u3001\u6587\u7AE0\u3001\u89C6\u9891\u6216\u7F51\u7AD9\u4F1A\u662F\uFF1A`,
  452. ({ question }) => `\u4ECE\u8FD9\u4E2A\u95EE\u9898\uFF1A${question}\uFF0C\u53EF\u4EE5\u5F15\u7533\u51FA\u8FD9\u4E9B\u95EE\u9898\uFF1A`
  453. ];
  454. const github_prompts = [
  455. ({ website }) => `${website}\u7684\u6700\u4F73\u5B9E\u8DF5\u662F\uFF1A`,
  456. ({ website }) => `${website}\u7684\u7C7B\u4F3C\u9879\u76EE\u662F\uFF1A`,
  457. ({ website }) => `${website}\u7684\u76F8\u5173\u4E66\u7C4D\u3001\u6587\u7AE0\u3001\u89C6\u9891\u6216\u7F51\u7AD9\u662F\uFF1A`
  458. ];
  459. function chatgpt_trigger(prompt_prepare, prompts) {
  460. const prepare_data = prompt_prepare();
  461. const prompt_texts = prompts.map((prompt) => prompt(prepare_data));
  462. GM_setValue("prompt_texts", prompt_texts);
  463. }
  464. const triggers = [
  465. {
  466. checker: () => menu_all.douban_book && location.href.includes("book.douban.com/subject"),
  467. prepare: () => {
  468. const title = $("meta[property='og:title']").attr("content");
  469. const author = $("meta[property='book:author']").attr("content");
  470. return { title, author };
  471. },
  472. prompts: douban_book_prompts
  473. },
  474. {
  475. checker: () => menu_all.zhihu && location.href.includes("zhihu.com/question"),
  476. prepare: () => {
  477. const question = $('meta[itemprop="name"]').attr("content");
  478. return { question };
  479. },
  480. prompts: [...question_prompts]
  481. },
  482. {
  483. checker: () => menu_all.hackernews && location.href.includes("news.ycombinator.com/item"),
  484. prepare: () => {
  485. const question = $("td.title > span.titleline > a").text();
  486. return { question };
  487. },
  488. prompts: [...question_prompts]
  489. },
  490. {
  491. checker: () => menu_all.github && location.href.includes("github.com"),
  492. prepare: () => {
  493. const parts = location.href.split("/");
  494. if (parts.length >= 5 && parts[parts.length - 2] && parts[parts.length - 1]) {
  495. const website = parts[parts.length - 2] + "/" + parts[parts.length - 1];
  496. return { website };
  497. }
  498. },
  499. prompts: github_prompts
  500. },
  501. {
  502. checker: () => menu_all.wikipedia && location.href.includes("wikipedia.org/wiki/"),
  503. prepare: () => {
  504. const title = $("h1#firstHeading").text();
  505. const summary = $("div.mw-parser-output p").first().text();
  506. return { title, summary };
  507. },
  508. prompts: [
  509. ({ title }) => `${title}\u7684\u5386\u53F2\u548C\u91CD\u8981\u4E8B\u4EF6\u6709\u54EA\u4E9B\uFF1F`,
  510. ({ title }) => `${title}\u4E0E\u5176\u4ED6\u76F8\u5173\u4E3B\u9898\u7684\u6BD4\u8F83\u548C\u5BF9\u6BD4\u4F1A\u662F\uFF1A`,
  511. ({ title }) => `${title}\u7684\u4E3B\u8981\u89C2\u70B9\u5217\u6210\u8868\u683C\u4F1A\u662F\uFF1A`,
  512. ({ title }) => `${title}\u7684\u5173\u952E\u6982\u5FF5\u548C\u672F\u8BED\u662F\u4EC0\u4E48\uFF1F`,
  513. ({ title }) => `${title}\u7684\u7C7B\u4F3C\u8BCD\u6761\u6216\u76F8\u5173\u7814\u7A76\u548C\u5B83\u4EEC\u7684\u533A\u522B\u4F1A\u662F\uFF1A`
  514. ]
  515. },
  516. {
  517. checker: () => menu_all.nytimes && location.href.includes("nytimes.com"),
  518. prepare: () => {
  519. const articleTitle = $("h1").text();
  520. return { question: articleTitle };
  521. },
  522. prompts: [...question_prompts]
  523. },
  524. {
  525. checker: () => menu_all.baidu && location.href.includes("www.baidu.com/s"),
  526. prepare: () => {
  527. const keyword = $("input#kw").val();
  528. return { keyword };
  529. },
  530. prompts: [
  531. ({ keyword }) => `\u5173\u4E8E"${keyword}"\u7684\u6700\u65B0\u65B0\u95FB\u6709\u54EA\u4E9B\uFF1F`,
  532. ({ keyword }) => `"${keyword}"\u7684\u5B9A\u4E49\u548C\u89E3\u91CA\u662F\u4EC0\u4E48\uFF1F`,
  533. ({ keyword }) => `\u5BF9\u4E8E"${keyword}"\u8FD9\u4E2A\u8BDD\u9898\uFF0C\u4F60\u6709\u4EC0\u4E48\u89C2\u70B9\u6216\u770B\u6CD5\uFF1F`,
  534. ({ keyword }) => `\u8DDF"${keyword}"\u76F8\u5173\u7684\u4EBA\u7269\u6216\u4E8B\u4EF6\u6709\u54EA\u4E9B\uFF1F`,
  535. ({ keyword }) => `\u6700\u8FD1\u8DDF"${keyword}"\u76F8\u5173\u7684\u70ED\u95E8\u8BDD\u9898\u662F\u4EC0\u4E48\uFF1F`
  536. ]
  537. },
  538. {
  539. checker: () => menu_all.reddit && location.href.includes("reddit.com"),
  540. prepare: () => {
  541. const postTitle = $("h1._eYtD2XCVieq6emjKBH3m").text();
  542. const postContent = $("div._3W_31WoaKsKsZfNldTiz5M").first().text();
  543. return { postTitle, postContent };
  544. },
  545. prompts: [
  546. ({ postTitle }) => `\u5173\u4E8E"${postTitle}"\uFF0C\u4F60\u6709\u4EC0\u4E48\u60F3\u6CD5\u6216\u8BC4\u8BBA\uFF1F`,
  547. ({ postTitle }) => `\u80FD\u7ED9\u5927\u5BB6\u5206\u4EAB\u4E00\u4E9B"${postTitle}"\u7684\u76F8\u5173\u4FE1\u606F\u5417\uFF1F`,
  548. ({ postTitle }) => `\u5728"${postTitle}"\u7684\u8BA8\u8BBA\u4E2D\uFF0C\u6709\u54EA\u4E9B\u89C2\u70B9\u6216\u610F\u89C1\u6700\u503C\u5F97\u5173\u6CE8\uFF1F`,
  549. ({ postTitle }) => `\u5BF9\u4E8E"${postTitle}"\uFF0C\u4F60\u7684\u770B\u6CD5\u662F\u5426\u4E0E\u5176\u4ED6\u4EBA\u4E0D\u540C\uFF1F`,
  550. ({ postTitle }) => `\u8BF7\u7B80\u8981\u4ECB\u7ECD\u4E00\u4E0B"${postTitle}"\u7684\u4E3B\u8981\u5185\u5BB9\u548C\u80CC\u666F\u3002`
  551. ]
  552. },
  553. {
  554. checker: () => menu_all.google && location.href.includes("google.com/search?q="),
  555. prepare: () => {
  556. const keyword = $("input[name='q']").val();
  557. return { keyword };
  558. },
  559. prompts: [
  560. ({ keyword }) => `\u5173\u4E8E"${keyword}"\u7684\u6700\u65B0\u641C\u7D22\u7ED3\u679C\u6709\u54EA\u4E9B\uFF1F`,
  561. ({ keyword }) => `\u5BF9\u4E8E"${keyword}"\u8FD9\u4E2A\u8BDD\u9898\uFF0C\u4F60\u6709\u4EC0\u4E48\u89C2\u70B9\u6216\u770B\u6CD5\uFF1F`,
  562. ({ keyword }) => `\u8DDF"${keyword}"\u76F8\u5173\u7684\u4EBA\u7269\u6216\u4E8B\u4EF6\u6709\u54EA\u4E9B\uFF1F`,
  563. ({ keyword }) => `\u6700\u8FD1\u8DDF"${keyword}"\u76F8\u5173\u7684\u70ED\u95E8\u8BDD\u9898\u662F\u4EC0\u4E48\uFF1F`
  564. ]
  565. },
  566. {
  567. checker: () => menu_all.youtube && location.href.includes("youtube.com/watch"),
  568. prepare: () => {
  569. const metaTitle = $('meta[name="title"]').attr("content");
  570. return { metaTitle };
  571. },
  572. prompts: [
  573. ({ metaTitle }) => `\u5173\u4E8E"${metaTitle}"\u7684\u89C2\u70B9\u6216\u8BC4\u8BBA\u6709\u54EA\u4E9B\uFF1F`,
  574. ({ metaTitle }) => `\u80FD\u7ED9\u5927\u5BB6\u5206\u4EAB\u4E00\u4E9B\u5173\u4E8E"${metaTitle}"\u7684\u76F8\u5173\u4FE1\u606F\u5417\uFF1F`,
  575. ({ metaTitle }) => `\u5728"${metaTitle}"\u7684\u8BA8\u8BBA\u4E2D\uFF0C\u6709\u54EA\u4E9B\u89C2\u70B9\u6216\u610F\u89C1\u6700\u503C\u5F97\u5173\u6CE8\uFF1F`,
  576. ({ metaTitle }) => `\u5BF9\u4E8E"${metaTitle}"\uFF0C\u4F60\u7684\u770B\u6CD5\u662F\u5426\u4E0E\u5176\u4ED6\u4EBA\u4E0D\u540C\uFF1F`,
  577. ({ metaTitle }) => `\u8BF7\u7B80\u8981\u4ECB\u7ECD\u4E00\u4E0B"${metaTitle}"\u7684\u4E3B\u8981\u5185\u5BB9\u548C\u80CC\u666F\u3002`
  578. ]
  579. }
  580. ];
  581. triggers.forEach((trigger) => {
  582. trigger.checker() && chatgpt_trigger(trigger.prepare, trigger.prompts);
  583. });
  584. let last_trigger_time = +/* @__PURE__ */ new Date();
  585. $(() => {
  586. if (location.href.includes("chat.openai")) {
  587. GM_addValueChangeListener("prompt_texts", (name, old_value, new_value) => {
  588. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  589. return;
  590. }
  591. last_trigger_time = +/* @__PURE__ */ new Date();
  592. setTimeout(() => __async(this, null, function* () {
  593. const prompt_texts = new_value;
  594. if (prompt_texts.length > 0) {
  595. let firstTime = true;
  596. while (prompt_texts.length > 0) {
  597. if (!firstTime) {
  598. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  599. }
  600. if (!firstTime && (0, import_chatgpt.getRegenerateButton)() == void 0) {
  601. continue;
  602. }
  603. firstTime = false;
  604. const prompt_text = prompt_texts.shift();
  605. (0, import_chatgpt.send)(prompt_text);
  606. }
  607. }
  608. }), 0);
  609. GM_setValue("prompt_texts", []);
  610. });
  611. }
  612. });
  613. })();
  614. })();