[Community Script] Code Studio for AI Studio: Fix Broken Code Blocks, Live Edit, Diff & Preview

If you regularly run into split HTML code blocks, swallowed trailing notes, or unparsed Markdown fences in Google AI Studio, I built a lightweight vanilla JS console script to fix them on demand and upgrade code blocks into an interactive mini-editor.

What It Fixes & Adds

  • Repairs Broken Rendering: Automatically stitches split HTML blocks back together, separates trailing notes swallowed inside code blocks, and parses raw unrendered Markdown/fences.

  • In-Place Editor & Diff Viewer: Edit code directly in the chat (with Tab indenting and Ctrl+S to save), track changes with a fast unified diff view, and revert anytime.

  • Sandboxed Live Preview: Preview HTML and SVG snippets inside an isolated sandbox iframe (with mobile, tablet, and full-width toggles) without touching the AI Studio origin.

  • Search, Syntax Highlighting & Bulk Download: Includes regex find-and-replace, line numbers, word wrap, fullscreen focus mode, auto-detected filenames, and one-click download for individual or all blocks.

  • Safe & Reversible: Zero external dependencies, Trusted Types compliant (no innerHTML), stays idle unless you enable the optional Watch mode, and includes a one-click Restore DOM button to undo everything cleanly.

How to Use

  1. Open Google AI Studio and open your browser DevTools Console (F12 or Ctrl+Shift+J).

  2. Paste the script below and press Enter.

  3. Use the floating Code Studio HUD in the bottom-right corner, or use the keyboard shortcuts:

    • Alt + Shift + F: Run an on-demand scan and fix

    • Alt + Shift + H: Collapse or expand the HUD

Feedback and bug reports are welcome. Here’s the full script: https//greasyfork.org/en/scripts/607085-google-ai-studio-code-studio-fix-code-blocks-live-edit-diff-preview