您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Forcefully query and clean up ChatGPT DOM, keeping only the last 20 messages.
当前为
// ==UserScript== // @name ChatGPT DOM Cleanup (Forceful Querying) // @namespace http://tampermonkey.net/ // @version 1.5 // @description Forcefully query and clean up ChatGPT DOM, keeping only the last 20 messages. // @author YourName // @match https://chatgpt.com/* // @grant none // ==/UserScript== (function () { 'use strict'; // Configuration const MAX_VISIBLE_MESSAGES = 20; // Number of messages to keep in the DOM const CLEANUP_INTERVAL = 2000; // Interval for cleanup in milliseconds // Function to clean up the conversation DOM function cleanUpMessages() { const messageElements = document.querySelectorAll('[data-testid^="conversation-turn"]'); console.log(`Found ${messageElements.length} messages in the DOM.`); // If there are more messages than allowed, remove the oldest ones if (messageElements.length > MAX_VISIBLE_MESSAGES) { const excessMessages = Array.from(messageElements).slice(0, messageElements.length - MAX_VISIBLE_MESSAGES); excessMessages.forEach(el => el.remove()); console.log(`Removed ${excessMessages.length} old messages.`); } else { console.log('No messages need to be removed.'); } } // Repeated cleanup process function startRepeatedCleanup() { console.log('Starting repeated cleanup process...'); setInterval(() => { cleanUpMessages(); // Forcefully query and clean up messages }, CLEANUP_INTERVAL); } // Wait for the page to fully load window.addEventListener('load', () => { console.log('Page fully loaded. Starting initialization...'); startRepeatedCleanup(); }); })();