function hideOldMessages() { const thread = document.querySelector("#thread"); if (!thread) return;
const messages = Array.from(thread.querySelectorAll("article")); if (messages.length > MAX_VISIBLE_MESSAGES) { messages.forEach((msg, idx) => { msg.style.display = (idx < messages.length - MAX_VISIBLE_MESSAGES) ? "none" : ""; }); createShowAllButton(messages); } else { // If there are few messages, ensure they are visible and remove button if exists messages.forEach(msg => (msg.style.display = "")); const btn = document.getElementById("showAllMessagesBtn"); if (btn) btn.remove(); } }
// Attach the message observer to the current #thread function attachToThread() { const container = document.querySelector("#thread"); if (!container || container === currentThread) { return; // nothing new }
currentThread = container;
if (threadObserver) { threadObserver.disconnect(); }
// ==UserScript==
// @name ChatGPT - Hide Old Messages (New DOM, SPA Safe)
// @namespace https://openai.com/
// @version 1.3
// @description מסתיר הודעות ישנות בצ'אט של GPT ב־#thread article, עם כפתור הצג הכול (works across sidebar navigation)
// @author Ross M + tweak
// @license MIT
// @match https://chatgpt.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const MAX_VISIBLE_MESSAGES = 8;
let currentThread = null; // currently observed #thread element
let threadObserver = null; // MutationObserver for messages
function createShowAllButton(messages) {
console.log("✅ button Tampermonkey נטען");
const existing = document.getElementById("showAllMessagesBtn");
if (existing) return;
const btn = document.createElement("button");
btn.textContent = "SHOW";
btn.id = "showAllMessagesBtn";
Object.assign(btn.style, {
position: "fixed",
top: "50px",
right: "10px",
zIndex: 9999,
padding: "10px",
backgroundColor: "#10a37f",
color: "#fff",
border: "none",
borderRadius: "5px",
cursor: "pointer",
fontSize: "14px"
});
btn.onclick = () => {
messages.forEach(msg => msg.style.display = "");
btn.remove();
};
document.body.appendChild(btn);
}
function hideOldMessages() {
const thread = document.querySelector("#thread");
if (!thread) return;
const messages = Array.from(thread.querySelectorAll("article"));
if (messages.length > MAX_VISIBLE_MESSAGES) {
messages.forEach((msg, idx) => {
msg.style.display = (idx < messages.length - MAX_VISIBLE_MESSAGES) ? "none" : "";
});
createShowAllButton(messages);
} else {
// If there are few messages, ensure they are visible and remove button if exists
messages.forEach(msg => (msg.style.display = ""));
const btn = document.getElementById("showAllMessagesBtn");
if (btn) btn.remove();
}
}
// Attach the message observer to the current #thread
function attachToThread() {
const container = document.querySelector("#thread");
if (!container || container === currentThread) {
return; // nothing new
}
currentThread = container;
if (threadObserver) {
threadObserver.disconnect();
}
threadObserver = new MutationObserver(hideOldMessages);
threadObserver.observe(container, { childList: true, subtree: true });
// Run once immediately for the currently loaded messages
hideOldMessages();
}
// Watch the whole app for SPA route changes and DOM swaps of #thread
const appObserver = new MutationObserver(() => {
attachToThread();
});
// Start observing the whole document for changes
appObserver.observe(document.body, { childList: true, subtree: true });
// Initial run in case #thread is already present
attachToThread();
})();