Google AI Studio - Performance & UI Optimization

Advanced performance optimizations for Google AI Studio. Features zero-latency UI, auto-expanding text areas, and reduced browser rendering overhead.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Google AI Studio - Performance & UI Optimization
// @namespace    https://aistudio.google.com/
// @version      1.0.2.1
// @description  Advanced performance optimizations for Google AI Studio. Features zero-latency UI, auto-expanding text areas, and reduced browser rendering overhead.
// @author       John
// @match        https://aistudio.google.com/*
// @grant        GM_addStyle
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const css = `
        /* 1. RENDERING PIPELINE OPTIMIZATION */
        *, *::before, *::after {
            transition: none !important;
            animation: none !important;
            backdrop-filter: none !important;
            box-shadow: none !important;
            text-shadow: none !important;
        }

        /* 2. INTERFACE COLOR SCHEME (High-Contrast Dark) */
        body,
        mat-sidenav-container,
        mat-sidenav-content,
        .scroll-container,
        .monaco-editor,
        .monaco-editor-background {
            background-color: rgb(25, 25, 25) !important; /* This is #191919 */
            color: #e0e0e0 !important;
        }

        /* 3. GROUNDING TOOL SPACING & COLOR FIX */
        /* Forces the container background to #252525 while preserving button styles */
        .content-container:has(.enabled-tool),
        .enabled-tool {
            background-color: #252525 !important;
            border-radius: 4px !important;
            padding: 4px 8px !important;
        }

        /* 4. CONTENT LAYOUT & SPACING CONTEXT */
        ms-chat-turn,
        .turn-container,
        .history-item {
            background: rgb(25, 25, 25) !important;
            border: none !important;

            /* Spacing Logic: 5px Lateral, 25px Vertical Offset */
            padding-left: 5px !important;
            padding-right: 5px !important;
            padding-top: 25px !important;

            /* Margin Reset for Consistent Vertical Flow */
            margin: 5px !important;
            margin-top: 0px !important;

            /* Rendering Containment */
            contain: layout paint style !important;
            overflow: visible !important;
            display: block !important;
        }

        /* NESTED ELEMENT RESET */
        ms-chat-turn .message-content,
        ms-chat-turn mat-card,
        ms-chat-turn .model-message,
        ms-chat-turn .user-message,
        ms-chat-turn ms-message-content {
            padding: 0 !important;
            margin: 0 !important;
            background: transparent !important;
        }

        /* 5. DYNAMIC INPUT FIELD OPTIMIZATION */
        textarea {
            background-color: rgb(35, 35, 35) !important;
            color: #ffffff !important;
            border: 1px solid #555 !important;
            border-radius: 0px !important;
            padding: 15px !important;
            will-change: contents !important;

            /* Native Layout-based Resizing */
            field-sizing: content !important;
            max-height: 80vh !important;
            min-height: 60px !important;
            height: auto !important;
            resize: none !important;
        }

        /* 6. SYSTEM SCROLLBAR STYLING */
        ::-webkit-scrollbar {
            width: 12px !important;
            background: rgb(25, 25, 25) !important;
        }
        ::-webkit-scrollbar-thumb {
            background: #444 !important;
            border: 1px solid rgb(25, 25, 25) !important;
        }

        /* 7. UI DE-CLUTTERING */
        .sparkle-container, .magic-overlay, .thinking-shimmer {
            display: none !important;
        }

        /* 8. HARDWARE-ACCELERATED COMPOSITING */
        .overflow-y-auto, main {
            will-change: scroll-position !important;
            transform: translateZ(0) !important;
        }
    `;

    const style = document.createElement('style');
    style.textContent = css;
    document.head.append(style);

    // PERFORMANCE ENGINES (Decoupled Scroll & Input Prediction)
    const originalAddEventListener = EventTarget.prototype.addEventListener;
    EventTarget.prototype.addEventListener = function(type, listener, options) {
        if (type === 'wheel' || type === 'mousewheel' || type === 'touchstart' || type === 'touchmove') {
            if (typeof options === 'object') {
                options.passive = true;
            } else {
                options = { passive: true };
            }
        }
        return originalAddEventListener.call(this, type, listener, options);
    };

    const optimizeInput = () => {
        const inputs = document.querySelectorAll('textarea');
        inputs.forEach(el => {
            if (el.getAttribute('spellcheck') !== 'false') {
                el.setAttribute('spellcheck', 'false');
                el.setAttribute('autocomplete', 'off');
            }
        });
    };

    window.addEventListener('click', optimizeInput, { passive: true });
    window.addEventListener('focus', optimizeInput, { passive: true, capture: true });

    console.log("AI Studio Performance Suite: Initialized.");

})();