Skip to content

Hopex-Development/chatgpt-dom-pruner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

ChatGPT DOM Pruner (Tampermonkey)

A lightweight userscript that keeps long ChatGPT conversations fast and responsive by automatically pruning the DOM.

Designed for engineers, power users, and anyone who works inside very long AI chats containing logs, code, and large responses.


Why This Exists

ChatGPT runs as a Single Page Application (SPA).
When a conversation grows large, the browser must maintain thousands of DOM nodes, which leads to:

  • scroll lag
  • layout recalculations
  • increased memory usage
  • GPU/CPU spikes
  • occasional UI freezes

This script solves the problem by applying a hybrid pruning strategy.


Core Strategy

The script continuously monitors the DOM and organizes conversation turns into three zones:

Recent turns - fully visible

The newest messages remain untouched for maximum readability.

Mid-range turns - soft collapsed

Older messages are hidden using modern browser rendering optimizations:

  • content-visibility
  • layout containment
  • reduced paint cost

This dramatically improves scroll performance without breaking React reconciliation.

Old turns - permanently removed

Very old messages are deleted to prevent DOM bloat.


Features

  • Automatic DOM pruning via MutationObserver
  • Hybrid collapse + delete strategy
  • Removes empty conversation turns
  • Toggle button (PRUNE ON / OFF)
  • Scroll position preservation
  • Low CPU overhead (no polling)
  • React-safe approach
  • Zero dependencies

Installation

1. Install Tampermonkey

https://www.tampermonkey.net/

2. Create a new userscript

Paste the script and save.

3. Reload ChatGPT

You should see a PRUNE ON button in the bottom-right corner.


Configuration

Inside the script:

const CFG = {
  keepFull: 80,   // newest turns kept fully visible
  keepSoft: 200,  // turns between keepFull and keepSoft are collapsed
};

Safety

This script intentionally avoids aggressive DOM mutations that could destabilize React. All operations are strictly visual. It does not:

  • Intercept network traffic.
  • Modify ChatGPT data.
  • Access prompts.
  • Inject external code.

Known Limitations

  • Deleted messages cannot be restored without reloading the conversation.
  • Browser search does not see collapsed content.
  • Extremely aggressive thresholds may cause minor scroll shifts.

Recommended Thresholds

Typical workstation:

keepFull: 60–100
keepSoft: 150–300

Low-memory laptop:

keepFull: 40–60
keepSoft: 120–180

About

ChatGPT DOM Pruner (Tampermonkey)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors