This commit is contained in:
F04C
2025-05-09 18:53:07 +08:00
commit 224eb18424
5 changed files with 96 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
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();
})();
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

+19
View File
@@ -0,0 +1,19 @@
{
"manifest_version": 3,
"name": "ChatGPT Long Message Hider",
"version": "1.0",
"description": "Hides long history elements in ChatGPT conversations to improve loading speed.",
"permissions": ["scripting"],
"host_permissions": ["https://chat.openai.com/*", "https://chatgpt.com/*"],
"content_scripts": [
{
"matches": ["https://chat.openai.com/*", "https://chatgpt.com/*"],
"js": ["content.js"]
}
],
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
}
}