Greasy Fork is available in English.

增强的AI聊天界面

增强各种AI聊天平台的UI,提供更好的用户体验

// ==UserScript==
// @name         增强的AI聊天界面
// @namespace    http://tampermonkey.net/
// @version      0.5.1
// @description  增强各种AI聊天平台的UI,提供更好的用户体验
// @match        http*://*.chatgpt.com/*
// @match        http*://*.oaifree.com/*
// @match        http*://*.aicnn.cn/*
// @match        http*://*.aicnn.xyz/*
// @match        http*://*.aivvm.com/*
// @match        http*://*.moonshot.cn/*
// @match        http*://*.aliyun.com/qianwen*
// @match        https://www.tiangong.cn/*
// @match        http*://*.chatglm.cn/*
// @match        https://claude.ai/*
// @match        https://chat.deepseek.com/*
// @include      https://*claude*/*
// @match        https://chat.kelaode.ai/*
// @grant        GM_addStyle
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const commonStyle = `
        pre > div.rounded-md > div.overflow-y-auto,
        .code-block__code {
            max-height: auto;
            overflow: auto;
            scrollbar-width: thin;
            scrollbar-color: #aaa #111;
        }
        pre > div.rounded-md > div.overflow-y-auto::-webkit-scrollbar,
        .code-block__code::-webkit-scrollbar {
            width: 8px;
            height: 8px;
        }
        pre > div.rounded-md > div.overflow-y-auto::-webkit-scrollbar-track,
        .code-block__code::-webkit-scrollbar-track {
            background: #111;
        }
        pre > div.rounded-md > div.overflow-y-auto::-webkit-scrollbar-thumb,
        .code-block__code::-webkit-scrollbar-thumb {
            background: #aaa;
            border-radius: 4px;
        }
        pre > div.rounded-md > div.overflow-y-auto::-webkit-scrollbar-thumb:hover,
        .code-block__code::-webkit-scrollbar-thumb:hover {
            background: #888;
        }
    `;

    const siteStyles = {
        kimi: `
            div[data-testid] div[data-index] div.MuiBox-root,
            div[class^=mainContent] div.MuiBox-root > div[class^=chatBottom_],
            #root > div > div[class*=mainContent] > div[class*=layoutContent] > div.MuiBox-root > div.MuiBox-root[class*=homepage] > div.MuiContainer-root.MuiContainer-maxWidthMd {
                max-width: 100% !important;
            }
            div[class^=mainContent] div[class^=chatInput_ ] div[class^=inputInner_] div[class^=editor] {
                max-height: 360px;
            }
            #scroll-list div[class^=chatItemBox_].MuiBox-root {
                max-width: 100%;
            }
            div.MuiBox-root[class^=homepage] div[class^=mainContent] div[class^=chatInput_ ] div[class^=inputInner_] div[class^=editor] {
                max-height: 600px;
            }
        `,
        deepseek: `
            div:has(> #latest-context-divider),
            div:has(> div > #chat-input) {
                width: 95% !important;
                max-width: 90vw;
            }
        `,
        tongyi: `
            div[class^=mainContent] div[class^=questionItem--],
            div[class^=mainContent] div[class^=answerItem--] {
                width: 90% !important;
                max-width: 90vw;
            }
        `,
        tiangong: `
            #app > div > div > main > div.overflow-y-scroll.w-full > div.search-content.relative.flex.w-full.flex-row.justify-center,
            #app > div > div > main > div.overflow-y-scroll.w-full > div.search-content.relative.flex.w-full.flex-row.justify-center > label.w-full.cursor-default.select-auto,
            label.w-full,
            :root {
                max-width: calc(100% - 100px);
                --search-max-width: calc(100% - 100px);
            }
        `,
        chatglm: `
            div.conversation-inner.dialogue > div.conversation-list.detail > div.item.conversation-item,
            .markdown-body.md-body {
                max-width: 95vw !important;
            }
        `,
        default: `
            .xl\\:max-w-\\[48rem\\] {
                width: 95% !important;
                max-width: 96% !important;
            }
            div.mx-auto.md\\:max-w-3xl,
            div.mx-auto.flex,
            body > div.flex.min-h-screen.w-full > div > main > div.top-5.z-10.mx-auto.w-full.max-w-2xl.md,
            body > div.flex.min-h-screen.w-full > div > main > div.mx-auto.w-full.max-w-2xl.px-1.md {
                max-width: calc(100% - 10px);
            }
            div.ProseMirror.break-words.ProseMirror-focused,
            body > div.flex.min-h-screen.w-full div.flex.flex-col div.flex.gap-2 div.mt-1.max-h-96.w-full.overflow-y-auto.break-words > div.ProseMirror.break-words {
                max-width: 100%;
            }
            body > div.flex.min-h-screen.w-full > div > main.max-w-7xl {
                max-width: 90rem;
            }
            main > div.composer-parent article > div.text-base > div.mx-auto,
            main article > div.text-base > div.mx-auto {
                max-width: 95%;
            }
        `
    };

    function applyStyle(site) {
        GM_addStyle(siteStyles[site] || siteStyles.default);
    }

    function enhanceUI() {
        const hostname = window.location.hostname;
        if (hostname.includes('moonshot.cn')) {
            applyStyle('kimi');
        } else if (hostname.includes('deepseek.com')) {
            applyStyle('deepseek');
        } else if (hostname.includes('aliyun.com')) {
            applyStyle('tongyi');
        } else if (hostname.includes('tiangong.cn')) {
            applyStyle('tiangong');
        } else if (hostname.includes('chatglm.cn')) {
            applyStyle('chatglm');
        } else {
            applyStyle('default');
        }
    }

    function addLinkHrefs() {
        document.querySelectorAll('div[data-message-id] a[rel="noreferrer"]').forEach(item => {
            if (!item.href) {
                item.href = item.innerText;
                item.target = "_blank";
            }
        });
    }

    GM_addStyle(commonStyle);
    
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', enhanceUI);
    } else {
        enhanceUI();
    }

    const observer = new MutationObserver(addLinkHrefs);
    observer.observe(document.body, { childList: true, subtree: true });
})();