{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreia5gqnde4vrkpjenn36o3dlv4tguhnp5ieq53ermzxenldgb5d2ou",
    "uri": "at://did:plc:lk3jfj3zq4k4wxnk474axylu/app.bsky.feed.post/3mfl56nha7ps2"
  },
  "path": "/t/optimize-chatgpt-for-long-conversations-with-automatic-summarization-and-adaptive-context-management/1089657#post_6",
  "publishedAt": "2026-02-24T01:00:43.000Z",
  "site": "https://community.openai.com",
  "textContent": "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.\n\nImportant: 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.\n\nRequirements — deliver the full script and nothing else but a short usage guide and selector list as specified below:\n\n  1. Top comment and metadata:\n\n\n  * Top comment must state: language and tested Firefox version, e.g.: “JavaScript (ES2023). Tested on Firefox 122 with FireMonkey.”\n\n  * Include brief install/use notes in the top comment.\n\n  * Do not use GM_* APIs. Use only standard browser APIs (IndexedDB, Web Crypto, DOM).\n\n\n\n  2. High-level description:\n\n\n  * 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.\n\n\n  3. Core behavior:\n\n\n  * Keep last N interactions in DOM and memory (configurable, default N = 10).\n\n  * Archive older messages into IndexedDB in compressed segments (configurable segment size, default 50 messages).\n\n  * Replace archived ranges in the DOM with a clickable placeholder that loads the archived segment on demand and restores original message nodes in order.\n\n  * Prefetch adjacent archived segments when the user approaches the archived boundary while scrolling.\n\n  * 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.\n\n  * Maintain minimal, recoverable metadata in an index store (segment id, first/last message id, count, timestamp, compressed flag).\n\n  * Use site-specific DOM selectors per supported site; fall back to heuristic detection if DOM changes. For each supported site include the selectors used.\n\n\n\n  4. Input responsiveness:\n\n\n  * 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.\n\n  * 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.\n\n\n\n  5. Privacy/security:\n\n\n  * All storage is local (IndexedDB); do not send any user data off-device.\n\n  * 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).\n\n\n\n  6. Performance:\n\n\n  * 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.\n\n  * Minimize DOM reflows: perform batch DOM updates and use placeholders.\n\n  * Provide token/message counters per segment to help reasoning about context-length.\n\n\n\n  7. Robustness:\n\n\n  * Handle partial/corrupt segments gracefully (show error, allow retry).\n\n  * Ensure single-writer semantics to a segment (use simple locking in IndexedDB meta store).\n\n  * Clean up orphaned placeholders if segments removed or schema upgraded.\n\n\n\n  8. Code quality:\n\n\n  * Clear modular functions with comments.\n\n  * Top comments on any code snippets must mention language and environment/version as requested.\n\n  * No external server dependencies.\n\n\n\n  9. Constraints:\n\n\n  * Do not intercept or modify outgoing network requests to the chat services.\n\n  * Do not assume access to non-public APIs.\n\n  * Prefer local helper libs; check a configurable file:// path for pako before loading remotely.\n\n  * Do not use GM_* APIs.\n\n\n\n  10. Deliverables (what the model’s output must include):\n\n\n  * The complete userscript code (single file) meeting the requirements above.\n\n  * A short usage guide (3–6 bullet points) explaining installing, configuring, and how to load archived messages.\n\n  * 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.\n\n  * If a site cannot be reliably supported, state that clearly in script comments and proceed with the other sites.\n\n\n\n\nTone and behavior for the generator:\n\n  * Be decisive: pick reasonable defaults and heuristics; do not ask the user clarification questions.\n\n  * Prioritize safety and privacy: store everything locally and provide encryption option.\n\n  * Make the script robust and conservative — prefer not to alter chat network behavior.\n\n\n\n\nNow: 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.",
  "title": "Optimize ChatGPT for Long Conversations with Automatic Summarization and Adaptive Context Management"
}