From 31d305b404855277aa19cba28e4b3f5a41c7d3c1 Mon Sep 17 00:00:00 2001 From: Malin Date: Mon, 30 Mar 2026 21:05:17 +0200 Subject: [PATCH] fix: skip comment articles, debounce MutationObserver to prevent RAM spike --- tldr-summarizer.user.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tldr-summarizer.user.js b/tldr-summarizer.user.js index 08b2988..876ff84 100644 --- a/tldr-summarizer.user.js +++ b/tldr-summarizer.user.js @@ -351,6 +351,10 @@ Summary:`; function injectFBBtn(article) { if (article.dataset.tldrDone) return; + + // Skip comments — they are articles nested inside another article + if (article.parentElement && article.parentElement.closest('[role="article"]')) return; + article.dataset.tldrDone = '1'; const text = extractFBText(article); @@ -371,8 +375,13 @@ Summary:`; } } + // Debounced scan — runs at most once per 600ms to avoid hammering the DOM + let scanTimer = null; function scanFB() { - document.querySelectorAll('div[role="article"]').forEach(injectFBBtn); + clearTimeout(scanTimer); + scanTimer = setTimeout(() => { + document.querySelectorAll('div[role="article"]').forEach(injectFBBtn); + }, 600); } // ── General articles / pages ──────────────────────────────────────────────