chatgpt-page-summary-button

🍓 let ChatGPT summary the web page you are reading in one click

目前為 2023-05-26 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name chatgpt-page-summary-button
  3. // @description 🍓 let ChatGPT summary the web page you are reading in one click
  4. // @author mefengl
  5. // @version 0.1.4
  6. // @namespace https://github.com/mefengl
  7. // @require https://cdn.jsdelivr.net/npm/@mozilla/readability@0.4.3/Readability.min.js
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  9. // @license MIT
  10. // @match *://*/*
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_addValueChangeListener
  14.  
  15. // @name:en ChatGPT Page Summary Button
  16. // @description:en 🍓 let ChatGPT summarize the web page you are reading in one click
  17. // @name:zh-CN ChatGPT 页面摘要按钮
  18. // @description:zh-CN 🍓 让 ChatGPT 一键总结您正在阅读的网页
  19. // @name:es Botón de resumen de página de ChatGPT
  20. // @description:es 🍓 permite que ChatGPT resuma la página web que estás leyendo con un solo clic
  21. // @name:hi ChatGPT पृष्ठ सारांश बटन
  22. // @description:hi 🍓 ChatGPT को वेबपेज जो आप पढ़ रहे हैं को एक क्लिक में संक्षेप में देने दें
  23. // @name:ar زر ملخص الصفحة لـ ChatGPT
  24. // @description:ar 🍓 دع ChatGPT يلخص صفحة الويب التي تقرأها بنقرة واحدة
  25. // @name:pt Botão de resumo de página do ChatGPT
  26. // @description:pt 🍓 permita que o ChatGPT resuma a página da web que você está lendo com um clique
  27. // @name:ru Кнопка резюме страницы ChatGPT
  28. // @description:ru 🍓 позволяет ChatGPT кратко описывать веб-страницу, которую вы читаете, одним щелчком мыши
  29. // @name:ja ChatGPTページ要約ボタン
  30. // @description:ja 🍓 ChatGPTで読んでいるWebページをワンクリックで要約
  31. // @name:de ChatGPT-Seitenzusammenfassungs-Button
  32. // @description:de 🍓 Lassen Sie ChatGPT die Webseite, die Sie gerade lesen, mit einem Klick zusammenfassen
  33. // @name:fr Bouton de résumé de page ChatGPT
  34. // @description:fr 🍓 laissez ChatGPT résumer la page Web que vous lisez en un seul clic
  35. // ==/UserScript==
  36. "use strict";
  37. (() => {
  38. var __create = Object.create;
  39. var __defProp = Object.defineProperty;
  40. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  41. var __getOwnPropNames = Object.getOwnPropertyNames;
  42. var __getProtoOf = Object.getPrototypeOf;
  43. var __hasOwnProp = Object.prototype.hasOwnProperty;
  44. var __commonJS = (cb, mod) => function __require() {
  45. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  46. };
  47. var __copyProps = (to, from, except, desc) => {
  48. if (from && typeof from === "object" || typeof from === "function") {
  49. for (let key of __getOwnPropNames(from))
  50. if (!__hasOwnProp.call(to, key) && key !== except)
  51. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  52. }
  53. return to;
  54. };
  55. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  56. // If the importer is in node compatibility mode or this is not an ESM
  57. // file that has been converted to a CommonJS file using a Babel-
  58. // compatible transform (i.e. "__esModule" has not been set), then set
  59. // "default" to the CommonJS "module.exports" for node compatibility.
  60. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  61. mod
  62. ));
  63. var __async = (__this, __arguments, generator) => {
  64. return new Promise((resolve, reject) => {
  65. var fulfilled = (value) => {
  66. try {
  67. step(generator.next(value));
  68. } catch (e) {
  69. reject(e);
  70. }
  71. };
  72. var rejected = (value) => {
  73. try {
  74. step(generator.throw(value));
  75. } catch (e) {
  76. reject(e);
  77. }
  78. };
  79. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  80. step((generator = generator.apply(__this, __arguments)).next());
  81. });
  82. };
  83.  
  84. // ../../packages/chatkit/dist/chatgpt/index.js
  85. var require_chatgpt = __commonJS({
  86. "../../packages/chatkit/dist/chatgpt/index.js"(exports, module) {
  87. "use strict";
  88. var __defProp2 = Object.defineProperty;
  89. var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
  90. var __getOwnPropNames2 = Object.getOwnPropertyNames;
  91. var __hasOwnProp2 = Object.prototype.hasOwnProperty;
  92. var __export = (target, all) => {
  93. for (var name in all)
  94. __defProp2(target, name, { get: all[name], enumerable: true });
  95. };
  96. var __copyProps2 = (to, from, except, desc) => {
  97. if (from && typeof from === "object" || typeof from === "function") {
  98. for (let key of __getOwnPropNames2(from))
  99. if (!__hasOwnProp2.call(to, key) && key !== except)
  100. __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
  101. }
  102. return to;
  103. };
  104. var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
  105. var chatgpt_exports = {};
  106. __export(chatgpt_exports, {
  107. getContinueGeneratingButton: () => getContinueGeneratingButton,
  108. getConversation: () => getConversation,
  109. getLastResponse: () => getLastResponse,
  110. getLastResponseElement: () => getLastResponseElement,
  111. getModelSelectButton: () => getModelSelectButton,
  112. getNewModelSelectButtons: () => getNewModelSelectButtons,
  113. getRegenerateButton: () => getRegenerateButton,
  114. getStopGeneratingButton: () => getStopGeneratingButton,
  115. getSubmitButton: () => getSubmitButton,
  116. getTextarea: () => getTextarea,
  117. getTextareaValue: () => getTextareaValue,
  118. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  119. isConversationStarted: () => isConversationStarted,
  120. isGenerating: () => isGenerating,
  121. isHorizontalConversation: () => isHorizontalConversation,
  122. onSend: () => onSend,
  123. regenerate: () => regenerate,
  124. send: () => send,
  125. setHorizontalConversation: () => setHorizontalConversation,
  126. setPromptListener: () => setPromptListener2,
  127. setPureConversation: () => setPureConversation,
  128. setTextarea: () => setTextarea,
  129. waitForIdle: () => waitForIdle
  130. });
  131. module.exports = __toCommonJS(chatgpt_exports);
  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 getRegenerateButton() {
  147. const form = document.querySelector("form");
  148. if (!form)
  149. return;
  150. const buttons = form.querySelectorAll("button");
  151. const result = Array.from(buttons).find((button) => {
  152. var _a;
  153. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("regenerate");
  154. });
  155. return result;
  156. }
  157. function getContinueGeneratingButton() {
  158. const form = document.querySelector("form");
  159. if (!form)
  160. return;
  161. const buttons = form.querySelectorAll("button");
  162. const result = Array.from(buttons).find((button) => {
  163. var _a;
  164. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("continue generating");
  165. });
  166. return result;
  167. }
  168. function getStopGeneratingButton() {
  169. const form = document.querySelector("form");
  170. if (!form)
  171. return;
  172. const buttons = form.querySelectorAll("button");
  173. const result = Array.from(buttons).find((button) => {
  174. var _a;
  175. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("stop generating");
  176. });
  177. return result;
  178. }
  179. function getLastResponseElement() {
  180. const responseElements = document.querySelectorAll(".group.w-full");
  181. return responseElements[responseElements.length - 1];
  182. }
  183. function getLastResponse() {
  184. const lastResponseElement = getLastResponseElement();
  185. if (!lastResponseElement)
  186. return;
  187. const lastResponse = lastResponseElement.textContent;
  188. return lastResponse;
  189. }
  190. function getTextareaValue() {
  191. var _a;
  192. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  193. }
  194. function setTextarea(message) {
  195. const textarea = getTextarea();
  196. if (!textarea)
  197. return;
  198. textarea.value = message;
  199. textarea.dispatchEvent(new Event("input"));
  200. }
  201. function send(message) {
  202. setTextarea(message);
  203. const textarea = getTextarea();
  204. if (!textarea)
  205. return;
  206. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  207. }
  208. function regenerate() {
  209. const regenerateButton = getRegenerateButton();
  210. if (!regenerateButton)
  211. return;
  212. regenerateButton.click();
  213. }
  214. function onSend(callback) {
  215. const textarea = getTextarea();
  216. if (!textarea)
  217. return;
  218. textarea.addEventListener("keydown", function(event) {
  219. if (event.key === "Enter" && !event.shiftKey) {
  220. callback();
  221. }
  222. });
  223. const sendButton = getSubmitButton();
  224. if (!sendButton)
  225. return;
  226. sendButton.addEventListener("mousedown", callback);
  227. }
  228. function isGenerating() {
  229. var _a, _b;
  230. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  231. }
  232. function waitForIdle() {
  233. return new Promise((resolve) => {
  234. const interval = setInterval(() => {
  235. if (!isGenerating()) {
  236. clearInterval(interval);
  237. resolve();
  238. }
  239. }, 1e3);
  240. });
  241. }
  242. function setPromptListener2(key = "prompt_texts") {
  243. let last_trigger_time = +/* @__PURE__ */ new Date();
  244. if (location.href.includes("chat.openai")) {
  245. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  246. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  247. return;
  248. }
  249. last_trigger_time = +/* @__PURE__ */ new Date();
  250. setTimeout(() => __async(this, null, function* () {
  251. const prompt_texts = new_value;
  252. if (prompt_texts.length > 0) {
  253. let firstTime = true;
  254. while (prompt_texts.length > 0) {
  255. if (!firstTime) {
  256. yield new Promise((resolve) => setTimeout(resolve, 2e3));
  257. }
  258. if (!firstTime && isGenerating()) {
  259. continue;
  260. }
  261. firstTime = false;
  262. const prompt_text = prompt_texts.shift() || "";
  263. send(prompt_text);
  264. }
  265. }
  266. }), 0);
  267. GM_setValue(key, []);
  268. }));
  269. }
  270. }
  271. function getConversation() {
  272. var _a, _b;
  273. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  274. }
  275. function getModelSelectButton() {
  276. const conversation = getConversation();
  277. if (!conversation)
  278. return;
  279. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  280. var _a;
  281. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  282. });
  283. }
  284. function getNewModelSelectButtons() {
  285. return Array.from(document.querySelectorAll("[class^='group/button']"));
  286. }
  287. function hasNewModelSelectButtons() {
  288. return getNewModelSelectButtons().length > 0;
  289. }
  290. function isConversationStarted() {
  291. return !getModelSelectButton();
  292. }
  293. function setPureConversation() {
  294. const conversation = getConversation();
  295. if (!conversation)
  296. return;
  297. const firstChild = conversation.firstChild;
  298. if (!firstChild)
  299. return;
  300. const newDiv = document.createElement("div");
  301. conversation.insertBefore(newDiv, firstChild.nextSibling);
  302. }
  303. function isHorizontalConversation() {
  304. const conversation = getConversation();
  305. if (!conversation)
  306. return true;
  307. if (!isConversationStarted())
  308. return true;
  309. return conversation.classList.contains("grid");
  310. }
  311. function setHorizontalConversation() {
  312. if (isHorizontalConversation())
  313. return;
  314. setPureConversation();
  315. const conversation = getConversation();
  316. if (!conversation)
  317. return;
  318. conversation.classList.remove("flex", "flex-col", "items-center");
  319. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  320. }
  321. }
  322. });
  323.  
  324. // ../../packages/chatkit/chatgpt.js
  325. var require_chatgpt2 = __commonJS({
  326. "../../packages/chatkit/chatgpt.js"(exports, module) {
  327. module.exports = require_chatgpt();
  328. }
  329. });
  330.  
  331. // src/index.ts
  332. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  333.  
  334. // src/createButton/index.ts
  335. function createButton(callback) {
  336. if (window.location.href.includes("chat.openai")) {
  337. return;
  338. }
  339. const hideRight = document.title.match(/[\u4e00-\u9fa5]/) ? "-130px" : "-120px";
  340. const button = document.createElement("button");
  341. button.innerHTML = "\u7F51\u9875\u603B\u7ED3";
  342. button.style.position = "fixed";
  343. button.style.width = "140px";
  344. button.style.top = "180px";
  345. button.style.right = hideRight;
  346. button.style.zIndex = "999999";
  347. button.style.backgroundColor = "#F8BBC6";
  348. button.style.color = "#fff";
  349. button.style.opacity = "0.8";
  350. button.style.border = "none";
  351. button.style.borderRadius = "4px";
  352. button.style.padding = "10px 16px";
  353. button.style.fontSize = "18px";
  354. button.style.cursor = "pointer";
  355. button.style.transition = "right 0.3s";
  356. document.body.appendChild(button);
  357. button.addEventListener("mouseenter", () => {
  358. button.style.right = "-10px";
  359. });
  360. button.addEventListener("mouseleave", () => {
  361. button.style.right = hideRight;
  362. });
  363. document.addEventListener("fullscreenchange", () => {
  364. if (document.fullscreenElement) {
  365. button.style.display = "none";
  366. } else {
  367. button.style.display = "block";
  368. }
  369. });
  370. button.addEventListener("click", callback);
  371. }
  372. var createButton_default = createButton;
  373.  
  374. // src/SimpleArticleSegmentation/index.ts
  375. var MIN_PARAGRAPH_LENGTH = 1600;
  376. var MAX_PARAGRAPH_LENGTH = 1800;
  377. var SimpleArticleSegmentation = class {
  378. constructor(text) {
  379. this.text = text;
  380. }
  381. segment() {
  382. const paragraphs = [];
  383. const sentences = this.text.split(new RegExp("(?<=[.!?])\\s+"));
  384. let paragraph = "";
  385. for (const sentence of sentences) {
  386. if (paragraph.length + sentence.length + 1 <= MAX_PARAGRAPH_LENGTH) {
  387. paragraph += (paragraph.length > 0 ? " " : "") + sentence;
  388. } else {
  389. if (paragraph.length >= MIN_PARAGRAPH_LENGTH) {
  390. paragraphs.push(paragraph);
  391. paragraph = sentence;
  392. } else {
  393. paragraph += " " + sentence;
  394. }
  395. }
  396. }
  397. if (paragraph.length >= MIN_PARAGRAPH_LENGTH) {
  398. paragraphs.push(paragraph);
  399. }
  400. return paragraphs;
  401. }
  402. };
  403. var SimpleArticleSegmentation_default = SimpleArticleSegmentation;
  404.  
  405. // src/getParagraphs/index.ts
  406. function getParagraphs() {
  407. try {
  408. let docClone = document.cloneNode(true);
  409. let article = new Readability(docClone).parse();
  410. if (article && article.textContent) {
  411. const segmenter = new SimpleArticleSegmentation_default(article.textContent);
  412. const paragraphs = segmenter.segment();
  413. for (let i = 0; i < paragraphs.length; i++) {
  414. paragraphs[i] = paragraphs[i].trim();
  415. }
  416. return paragraphs;
  417. } else {
  418. console.warn("Readability.js could not extract any text content from this page.");
  419. return [];
  420. }
  421. } catch (error) {
  422. console.error("An error occurred while using Readability.js:", error);
  423. return [];
  424. }
  425. }
  426. var getParagraphs_default = getParagraphs;
  427.  
  428. // src/index.ts
  429. function initialize() {
  430. return __async(this, null, function* () {
  431. yield new Promise((resolve) => window.addEventListener("load", resolve));
  432. yield new Promise((resolve) => setTimeout(resolve, 1e3));
  433. });
  434. }
  435. function main() {
  436. return __async(this, null, function* () {
  437. yield initialize();
  438. const key = "prompt_texts";
  439. (0, import_chatgpt.setPromptListener)(key);
  440. const summaryWeb = () => __async(this, null, function* () {
  441. const paragraphs = getParagraphs_default();
  442. console.log(paragraphs);
  443. const prompt_texts = paragraphs.map((paragraph) => {
  444. return `"""
  445. ${paragraph}
  446. """
  447. Summarize this paragraph into a bulleted list of the most important information, prefix with emoji. Use Markdown syntax to optimize the display format:`;
  448. });
  449. console.log(prompt_texts);
  450. GM_setValue(key, prompt_texts);
  451. });
  452. createButton_default(summaryWeb);
  453. });
  454. }
  455. (function() {
  456. main();
  457. })();
  458. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址