Doozy

A wonderful day spent with ChatGPT

目前為 2023-08-02 提交的版本,檢視 最新版本

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