// ==UserScript== // @name ChatGPT 长对话卡顿优化 // @namespace chatgpt-conversation-pruner // @version 1.0 // @description chatgpt长对话卡顿是因为前端一次性加载了全部对话,导致每次新增对话时要渲染的聊天太多,因此可以通过设置属性为display=none来部分解决,通过卸载部分DOM来进一步缓解。 // @match https://chatgpt.com/* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/559208/ChatGPT%20%E9%95%BF%E5%AF%B9%E8%AF%9D%E5%8D%A1%E9%A1%BF%E4%BC%98%E5%8C%96.user.js // @updateURL https://update.greasyfork.icu/scripts/559208/ChatGPT%20%E9%95%BF%E5%AF%B9%E8%AF%9D%E5%8D%A1%E9%A1%BF%E4%BC%98%E5%8C%96.meta.js // ==/UserScript== (function () { 'use strict'; /************* 🔧 状态参数(可动态修改) *************/ let KEEP_VISIBLE = 8; let HIDE_BEYOND = 10; let ENABLE_REMOVE = false; const BOOT_CHECK_INTERVAL = 500; // UI 状态持久化 key const UI_STATE_KEY = 'cgpt_pruner_ui_minimized_v1'; /*****************************************************/ function getTurns() { return Array.from( document.querySelectorAll('article[data-testid^="conversation-turn"]') ); } function prune() { const turns = getTurns(); const total = turns.length; if (total <= HIDE_BEYOND) return; const removeBefore = ENABLE_REMOVE ? total - HIDE_BEYOND : -1; const hideBefore = total - KEEP_VISIBLE; for (let i = 0; i < total; i++) { const el = turns[i]; if (ENABLE_REMOVE && i < removeBefore) { el.remove(); } else if (i < hideBefore) { el.style.display = 'none'; } } } function startObserver() { const observer = new MutationObserver(prune); observer.observe(document.body, { childList: true, subtree: true }); console.log('[ChatGPT Pruner] Observer started'); } function waitForChat() { const timer = setInterval(() => { if (getTurns().length > 0) { clearInterval(timer); prune(); startObserver(); } }, BOOT_CHECK_INTERVAL); } /************* 🪟 浮窗 UI(Shadow DOM + 最小化) *************/ function createPanel() { const host = document.createElement('div'); host.style.position = 'fixed'; host.style.bottom = '20px'; host.style.right = '20px'; host.style.zIndex = '999999'; document.body.appendChild(host); const shadow = host.attachShadow({ mode: 'open' }); shadow.innerHTML = `