ChatGPT UI Enhancer

Enhance ChatGPT interface with better UI features

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ChatGPT UI Enhancer
// @namespace    http://yournamespace.example.com
// @version      1.0
// @description  Enhance ChatGPT interface with better UI features
// @author       YourName
// @match        https://chat.openai.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Auto Dark Mode
    function enableDarkMode() {
        const body = document.body;
        if (!body.classList.contains("dark-mode")) {
            body.classList.add("dark-mode");
        }
    }

    function disableDarkMode() {
        const body = document.body;
        body.classList.remove("dark-mode");
    }

    // Add Export Button
    function addExportButton() {
        if (document.querySelector("#export-conversation")) return;

        const button = document.createElement("button");
        button.id = "export-conversation";
        button.textContent = "Export Conversation";
        button.style.cssText =
            "position: fixed; bottom: 20px; right: 20px; z-index: 9999; background-color: #4CAF50; color: white; padding: 10px; border: none; border-radius: 5px; cursor: pointer;";

        button.onclick = function () {
            const messages = Array.from(
                document.querySelectorAll(".flex-col .prose p")
            ).map((p) => p.textContent);
            const text = messages.join("\n\n");
            const blob = new Blob([text], { type: "text/plain" });
            const a = document.createElement("a");
            a.href = URL.createObjectURL(blob);
            a.download = "conversation.txt";
            a.click();
        };

        document.body.appendChild(button);
    }

    // Auto Resize Text Area
    function autoResizeTextArea() {
        const textArea = document.querySelector("textarea");
        if (!textArea) return;

        textArea.style.height = "auto";
        textArea.style.overflowY = "hidden";
        textArea.addEventListener("input", function () {
            this.style.height = "auto";
            this.style.height = this.scrollHeight + "px";
        });
    }

    // Observe and Apply Changes
    const observer = new MutationObserver(() => {
        addExportButton();
        autoResizeTextArea();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true,
    });

    // Toggle Dark Mode
    enableDarkMode();
})();