// ==UserScript== // @name ChatGPT对话导出工具-轻松提取聊天记录导出至本地📄 // @namespace https://h5ma.cn/caicats // @version 1.0 // @description 一键将ChatGPT网站和国内相关镜像站的聊天记录导出为HTML或Markdown,轻松提取GPT聊天记录,让你在本地上就能使用看! // @author @caicats // @match https://chat.openai.com/* // @match https://new.oaifree.com/** // @match https://share.github.cn.com/** // @match https://chat.openai.com/** // @match https://chatgpt.com/** // @match https://*.oaifree.com/** // @match https://share.github.cn.com/** // @match https://cc.plusai.me/** // @match https://chat.chatgptplus.cn/** // @match https://chat.rawchat.cc/** // @match https://chat.sharedchat.cn/** // @match https://chat.gptdsb.com/** // @match https://chat.freegpts.org/** // @match https://gpt.github.cn.com/** // @match https://chat.aicnn.xyz/** // @match https://*.xyhelper.com.cn/** // @match https://oai.aitopk.com/** // @match https://www.opkfc.com/** // @match https://bus.hematown.com/** // @match https://chatgpt.dairoot.cn/** // @match https://plus.aivvm.com/** // @match https://sharechat.aischat.xyz/** // @match https://web.tu-zi.com/** // @match https://chat1.2233.ai/** // @match https://2233.ai/** // @match https://yesiamai.com/** // @match https://www.azs.ai/** // @match https://oai.253282.xyz/** // @match https://gpt.universalbus.cn/** // @grant none // @icon https://t1.gstatic.cn/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&size=32&url=https://chatgpt.com // ==/UserScript== (function() { 'use strict'; window.addEventListener('load', () => { createFloatingMenu(); }); function createFloatingMenu() { const menuContainer = document.createElement('div'); menuContainer.id = 'floating-menu'; menuContainer.style.position = 'fixed'; menuContainer.style.bottom = '80px'; menuContainer.style.right = '15px'; menuContainer.style.zIndex = '10000'; menuContainer.style.display = 'flex'; menuContainer.style.flexDirection = 'column'; menuContainer.style.alignItems = 'center'; menuContainer.style.gap = '10px'; // Main button as expand icon const mainButton = document.createElement('button'); mainButton.id = 'main-button'; mainButton.style.width = '40px'; mainButton.style.height = '40px'; mainButton.style.borderRadius = '50%'; mainButton.style.border = 'none'; mainButton.style.backgroundColor = '#4cafa3'; mainButton.style.color = 'white'; mainButton.style.cursor = 'pointer'; mainButton.style.fontSize = '26px'; mainButton.textContent = '+'; let isExpanded = false; mainButton.addEventListener('click', () => { isExpanded = !isExpanded; toggleMenu(isExpanded, menuContainer); }); // Markdown button with orange background const markdownButton = createMenuButton('📄', '导出为 Markdown', exportChatAsMarkdown, '#FFA500'); // HTML button with orange background const htmlButton = createMenuButton('🌐', '导出为 HTML', exportChatAsHTML, '#FFA500'); // Sponsor button to redirect to the specified page const sponsorButton = createMenuButton('❤️', '使用教程', () => { window.open('https://h5ma.cn/gptdc', '_blank'); }, '#FF6347'); // Tomato color background for sponsor button menuContainer.appendChild(mainButton); menuContainer.appendChild(markdownButton); menuContainer.appendChild(htmlButton); menuContainer.appendChild(sponsorButton); document.body.appendChild(menuContainer); // Initially hide the menu buttons toggleMenu(false, menuContainer); } function createMenuButton(icon, text, onClick, bgColor) { const buttonContainer = document.createElement('div'); buttonContainer.style.position = 'relative'; const button = document.createElement('button'); button.className = 'menu-button'; button.style.width = '36px'; button.style.height = '36px'; button.style.borderRadius = '50%'; button.style.border = 'none'; button.style.backgroundColor = bgColor; // Set background color button.style.color = 'white'; button.style.cursor = 'pointer'; button.textContent = icon; button.addEventListener('click', onClick); buttonContainer.appendChild(button); return buttonContainer; } function toggleMenu(expand, menuContainer) { const buttons = menuContainer.querySelectorAll('.menu-button'); buttons.forEach(button => { button.style.display = expand ? 'block' : 'none'; }); } async function exportChatAsMarkdown() { try { let markdownContent = "# ChatGPT 对话记录\n\n"; let allElements = document.querySelectorAll('div.flex.flex-grow.flex-col.max-w-full'); allElements.forEach((element, index) => { let text = element.textContent.trim(); if (index % 2 === 0) { markdownContent += `## User\n${text}\n\n`; } else { markdownContent += `## Assistant\n${text}\n\n`; } }); download(markdownContent, 'chat-export.md', 'text/markdown'); } catch (error) { console.error("导出为 Markdown 时出错:", error); } } async function exportChatAsHTML() { try { let htmlContent = "