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.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

作者
piknockyou
日安装量
0
总安装量
4
评分
0 0 0
版本
2.8
创建于
2025-12-21
更新于
2026-01-01
大小
26.5 KB
许可证
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.