Greasy Fork

Greasy Fork is available in English.

ChatGPT回答导出到txt文件

目前功能:批量导出ChatGPT回答到txt文件

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ChatGPT回答导出到txt文件
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  目前功能:批量导出ChatGPT回答到txt文件
// @author       NONO星梦
// @match        https://chat.openai.com/chat
// @match        https://chat.openai.com/chat/*
// @match        https://chat.openai.com/auth/login
// @icon         https://chat.openai.com/favicon.ico
// @license      GPL-3.0
// @run-at       document-idie
// @grant none
// ==/UserScript==

(function () {
  'use strict';

  // Define the download button
  const downloadButton = document.createElement('button');
  downloadButton.innerText = '导出';
  downloadButton.style.position = 'fixed';
  downloadButton.style.bottom = '10px';
  downloadButton.style.right = '10px';
  downloadButton.style.zIndex = '99999';
  downloadButton.style.width = '50px';
  downloadButton.style.height = '32px';
  downloadButton.style.background= 'rgba(0, 0, 0, 0.3)';

  // Append the download button to the body
  document.body.appendChild(downloadButton);

  // Add a click event listener to the download button
  downloadButton.addEventListener('click', () => {
    // Find all div elements with class 'markdown'
    const markdownDivs = document.querySelectorAll('div.markdown');

    // Create a new blob that contains the text content of all p tags inside the markdown divs
    const contentBlob = new Blob(
      Array.from(markdownDivs).map((div) =>
        Array.from(div.querySelectorAll('p')).map((p) => {
          return p.innerText.replace(/{[^}\n]+}(?!\n)/g, "$&\n") + '\n\n'
        }).join('\n')
      ),
      { type: 'text/plain' }
    );

    // Create a new URL for the blob
    const contentUrl = URL.createObjectURL(contentBlob);

    // Create a new anchor element to trigger the download
    const downloadLink = document.createElement('a');
    downloadLink.href = contentUrl;
    downloadLink.download = 'markdown_content.txt';

    // Click the download link to trigger the download
    downloadLink.click();

    // Revoke the URL object to free up memory
    URL.revokeObjectURL(contentUrl);
  });
})();