Google AI Studio | Collapse/Expand All Code Blocks (Manual/Automatic)

Collapse/expand all code blocks with dual toolbar buttons, auto-collapse mode, and 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
6
Valutazione
0 0 0
Versione
2.8
Creato il
21/12/2025
Aggiornato il
01/01/2026
Dimensione
26,5 KB
Licenza
AGPL-3.0
Applica a

See screenshot at the bottom

Google AI Studio | Collapse/Expand All Code Blocks (Manual/Automatic)

Adds two toolbar buttons in Google AI Studio to collapse all or expand all code blocks instantly, plus an optional Auto‑Collapse mode for newly generated / lazy-loaded blocks.

What It Does

AI Studio chats can get clogged with long code snippets. This script gives you quick, native-feeling controls to manage code block visibility:

  • Collapse all code blocks (one click)
  • Expand all code blocks (one click)
  • Auto‑Collapse mode (optional): automatically collapses code blocks as they appear (lazy loading + streaming responses)

How to Use

Toolbar Buttons (top-right, next to ⋮)

  • Blue chevron up (Collapse): collapses all code blocks currently on the page.
  • Amber chevron down (Expand): expands all code blocks currently on the page.

Auto‑Collapse Mode (Hold Gesture)

  • Hold the Collapse button for ~1 second to toggle Auto‑Collapse ON/OFF.
  • While holding, you’ll see:
    • A hint tooltip (after ~0.5s)
    • A fill animation indicating the hold action
  • When toggled:
    • You’ll get a confirmation tooltip
    • The collapse button shows a clear active indicator (blue accent styling / filled look)

Key Features

  • Dual-button control: separate Collapse and Expand buttons (no mode cycling needed).
  • Auto‑Collapse for new blocks: newly added code blocks are collapsed automatically when Auto‑Collapse is ON.
  • Lazy loading support: uses a MutationObserver to catch code blocks loaded later (scrolling, navigation, generation).
  • SPA-aware toolbar injection: button persists across AI Studio navigation without manual refresh.
  • State persistence: saves Auto‑Collapse setting in userscript storage (GM storage via GM_setValue / GM_getValue).
  • Migration support: automatically migrates older v1.x stored settings to the new format.
  • Theme-friendly UI: hover effects work in both light/dark mode; icons use AI Studio’s native Material Symbols.

Notes

  • Designed for https://aistudio.google.com/ only.
  • Works in the top frame only (won’t run inside iframes).
  • Uses minimal styling and does not depend on external libraries.

Installation

  1. Install a userscript manager (Violentmonkey / Tampermonkey / Greasemonkey).
  2. Install the script.
  3. Open aistudio.google.com — the two chevron buttons appear in the top-right toolbar near the button.