function createOrUpdateBadge(hiddenCount) { let badge = document.getElementById("cgpt-hide-badge"); if (!badge) { badge = document.createElement("div"); badge.id = "cgpt-hide-badge"; badge.style.position = "fixed"; badge.style.bottom = "20px"; badge.style.right = "20px"; badge.style.zIndex = "99999"; badge.style.background = "rgba(0,0,0,0.8)"; badge.style.color = "#fff"; badge.style.padding = "8px 16px"; badge.style.borderRadius = "20px"; badge.style.fontSize = "14px"; badge.style.boxShadow = "0 2px 8px rgba(0,0,0,0.2)"; badge.style.userSelect = "none"; badge.style.pointerEvents = "none"; document.body.appendChild(badge); } badge.textContent = `Hidden: ${hiddenCount}`; } (function hideAllButRecentConversationTurns() { const SHOW_LAST_N = 30; // Number of most recent turns to show function hideOldTurns() { const articles = Array.from( document.querySelectorAll( 'article[data-testid^="conversation-turn-"]' ) ); // Extract numeric IDs and sort const sorted = articles .map((article) => ({ el: article, id: parseInt( article .getAttribute("data-testid") .replace("conversation-turn-", ""), 10 ), })) .filter((item) => !isNaN(item.id)) .sort((a, b) => a.id - b.id); // Hide all except the last N const toHide = sorted.slice(0, -SHOW_LAST_N); toHide.forEach((item) => { item.el.style.display = "none"; }); // Show the most recent N const toShow = sorted.slice(-SHOW_LAST_N); toShow.forEach((item) => { item.el.style.display = ""; }); createOrUpdateBadge(toHide.length); } // Wait for all articles to load first function waitForArticlesAndHide() { const observer = new MutationObserver((mutations, obs) => { const articles = document.querySelectorAll( 'article[data-testid^="conversation-turn-"]' ); // If articles exist and no new articles are being added for a short period, proceed if (articles.length > 0) { // Wait 1 second after the last mutation to ensure loading is done clearTimeout(window.__hideTurnsTimeout); window.__hideTurnsTimeout = setTimeout(() => { hideOldTurns(); obs.disconnect(); // Re-observe for future loads (e.g., when user scrolls up) waitForArticlesAndHide(); }, 1000); } }); observer.observe(document.body, { childList: true, subtree: true }); } waitForArticlesAndHide(); })();