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.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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.");

})();