ChatGPT UI Enhancer

Enhance ChatGPT interface with better UI features

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();