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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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.