// Function to remove old messages
function removeOldMessages() {
// Select all message containers
const messageContainers = document.querySelectorAll('div[data-testid^="conversation-turn-"]');
// Log the number of messages found
console.log(`Total messages found: ${messageContainers.length}`);
// Check if there are more than 5 messages
if (messageContainers.length > 5) {
// Calculate the number of messages to remove
const messagesToRemove = messageContainers.length - 5;
// Log the number of messages being removed
console.log(`Removing ${messagesToRemove} old messages.`);
// Remove the old messages
for (let i = 0; i < messagesToRemove; i++) {
messageContainers[i].remove();
// Log each removal
console.log(`Removed message ${i + 1}`);
}
} else {
console.log('No messages to remove.');
}
}
// Call the function initially to clean up old messages
removeOldMessages();
// Set an interval to repeatedly call the function every 5 seconds
setInterval(removeOldMessages, 5000);
Created
May 25, 2024 05:44
-
-
Save icedmoca/d84547986b7392582da9352813420c55 to your computer and use it in GitHub Desktop.
chatgpt remove old messages from browser cache
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment