Google AI Studio | Toggle Code Blocks

Toggle all code blocks open/closed in Google AI Studio with lazy loading support.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Autore
piknockyou
Installazioni giornaliere
1
Installazioni totali
2
Valutazione
0 0 0
Versione
1.4
Creato il
21/12/2025
Aggiornato il
22/12/2025
Dimensione
10,2 KB
Licenza
AGPL-3.0
Applica a

Google AI Studio | Toggle Code Blocks

Introduces the ability to manage code block visibility in Google AI Studio. Adds a toolbar button to instantly collapse or expand all code snippets for a cleaner workspace.

Features

  • Smart Initial Action: The first click always collapses all code blocks to immediately de-clutter the view.
  • Persistent Mode: Your preference (Collapse or Expand) is saved to local storage and persists across page reloads and different chats.
  • Lazy Loading Support: Automatically manages code blocks that appear as you scroll up or as the AI generates them in real-time.
  • Color-Coded Feedback:
    • Gray Icon: Inactive (Click to activate Collapse Mode).
    • Blue Icon: Collapse Mode active (New blocks will auto-collapse).
    • Amber Icon: Expand Mode active (New blocks will auto-expand).
  • Toolbar Integration: Adds a native-style button to the top-right toolbar that matches the Google AI Studio aesthetic.

Installation

Requirements

Steps

  1. Install a userscript manager.
  2. Install this script.
  3. Open any prompt in Google AI Studio.

Usage

  1. Locate the button: Look for the chevron icon in the toolbar next to the "More options" (⋮) button.
  2. First Click: Activates Collapse Mode (Blue). All current and future code blocks will stay closed.
  3. Second Click: Switches to Expand Mode (Amber). All current and future code blocks will stay open.
  4. Third Click: Toggles back to Collapse Mode (Blue).

How It Works

  • Persistence: Uses localStorage to remember your toggle state across page reloads and chat switches.
  • Lazy Load Observer: Watches for new ms-code-block elements being added to the DOM and automatically applies your chosen mode (Collapse/Expand) as they appear.
  • Smart Logic: Includes a per-block debounce (500ms) to prevent flickering during rapid scrolling or AI generation.
  • Toolbar Observer: Uses a MutationObserver to ensure the button persists in the toolbar during SPA navigation between chats.

Technical Details

  • Icon: Uses standard Material Symbols (expand_less, expand_more) natively available in the app resources.
  • Styling: Injects minimal CSS to match the native toolbar layout.