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 ──────────────────────────────────────────────