External Publication
Visit Post

Optimize ChatGPT for Long Conversations with Automatic Summarization and Adaptive Context Management

OpenAI Developer Community February 24, 2026
Source

You are an expert code assistant (not just a generic assistant) specializing in browser performance, large-context LLM UIs, and userscript development. Goal: produce a single-file FireMonkey userscript (Firefox) that implements client-side chat archiving and on-demand restoration to keep only the last N interactions in-memory/DOM and persist older interactions to disk (IndexedDB), specifically to avoid lag and re-encoding delays when chats get long. The script must work on the official, public chat web UIs with known DOMs: ChatGPT (chat .openai .com), Copilot Chat (microsoft .copilot.com), Google Gemini (gemini .google .com), Anthropic Claude (chat .anthropic.com), and DeepSeek official page. The script should be robust across these sites, non-invasive (must not modify server requests), and provide on-demand loading when the user scrolls or clicks placeholders.

Important: produce a complete, ready-to-install single FireMonkey userscript (one file) that works out-of-the-box without asking the user follow-up questions. When site-specific uncertainties arise, make reasonable defaults and implement heuristics so the script still functions. If a site cannot be supported reliably, clearly note that in the script comments and continue implementing support for the others. Do not prompt the user for additional input.

Requirements — deliver the full script and nothing else but a short usage guide and selector list as specified below:

  1. Top comment and metadata:
  • Top comment must state: language and tested Firefox version, e.g.: “JavaScript (ES2023). Tested on Firefox 122 with FireMonkey.”

  • Include brief install/use notes in the top comment.

  • Do not use GM_* APIs. Use only standard browser APIs (IndexedDB, Web Crypto, DOM).

  1. High-level description:
  • Include 1–2 short paragraphs (inside the script comments) describing the approach and tradeoffs, emphasizing how this reduces long-chat lag and improves typing responsiveness.
  1. Core behavior:
  • Keep last N interactions in DOM and memory (configurable, default N = 10).

  • Archive older messages into IndexedDB in compressed segments (configurable segment size, default 50 messages).

  • Replace archived ranges in the DOM with a clickable placeholder that loads the archived segment on demand and restores original message nodes in order.

  • Prefetch adjacent archived segments when the user approaches the archived boundary while scrolling.

  • Provide a small on-page UI (config button) to change N, segment size, toggle compression, toggle encryption, and adjust input buffering/debounce settings; persist settings in IndexedDB.

  • Maintain minimal, recoverable metadata in an index store (segment id, first/last message id, count, timestamp, compressed flag).

  • Use site-specific DOM selectors per supported site; fall back to heuristic detection if DOM changes. For each supported site include the selectors used.

  1. Input responsiveness:
  • Implement a safe local input buffering/debouncing layer that reduces processing on every keystroke while allowing immediate local editing and paste of very long prompts. Do not modify or suppress legitimate send/submit actions.

  • Where possible without changing outbound network requests, avoid triggering heavy UI re-encoding on each keypress by deferring non-essential processing (e.g., live-tokenization, autosave) until idle or on debounce.

  1. Privacy/security:
  • All storage is local (IndexedDB); do not send any user data off-device.

  • Offer an option to encrypt stored payloads with a passphrase; if enabled, derive a key from the passphrase using PBKDF2 and encrypt/decrypt using Web Crypto (AES-GCM).

  1. Performance:
  • Use gzip compression via pako when enabled. Prefer loading a locally available pako bundle from a configurable file:// path first; if absent, load pako dynamically from a trusted remote source as a fallback.

  • Minimize DOM reflows: perform batch DOM updates and use placeholders.

  • Provide token/message counters per segment to help reasoning about context-length.

  1. Robustness:
  • Handle partial/corrupt segments gracefully (show error, allow retry).

  • Ensure single-writer semantics to a segment (use simple locking in IndexedDB meta store).

  • Clean up orphaned placeholders if segments removed or schema upgraded.

  1. Code quality:
  • Clear modular functions with comments.

  • Top comments on any code snippets must mention language and environment/version as requested.

  • No external server dependencies.

  1. Constraints:
  • Do not intercept or modify outgoing network requests to the chat services.

  • Do not assume access to non-public APIs.

  • Prefer local helper libs; check a configurable file:// path for pako before loading remotely.

  • Do not use GM_* APIs.

  1. Deliverables (what the model’s output must include):
  • The complete userscript code (single file) meeting the requirements above.

  • A short usage guide (3–6 bullet points) explaining installing, configuring, and how to load archived messages.

  • For each supported site, a clear list of DOM selectors used and a short note on where they may need adjustment if the site UI changes.

  • If a site cannot be reliably supported, state that clearly in script comments and proceed with the other sites.

Tone and behavior for the generator:

  • Be decisive: pick reasonable defaults and heuristics; do not ask the user clarification questions.

  • Prioritize safety and privacy: store everything locally and provide encryption option.

  • Make the script robust and conservative — prefer not to alter chat network behavior.

Now: generate the FireMonkey userscript file that satisfies all the above requirements. Output only the userscript, the short usage guide bullets, and the per-site selector list as specified — no extra commentary.

Discussion in the ATmosphere

Loading comments...