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.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

Аўтар
piknockyou
Усталяванняў за дзень
0
Усяго ўсталяванняў
5
Рэйтынг
0 0 0
Версія
2.8
Створаны
21.12.2025
Абноўлены
01.01.2026
Памер
26.5 КБ
Ліцэнзія
AGPL-3.0
Ужываецца на

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.