fix: skip comment articles, debounce MutationObserver to prevent RAM spike

This commit is contained in:
2026-03-30 21:05:17 +02:00
parent b1caf1c028
commit 31d305b404

View File

@@ -351,6 +351,10 @@ Summary:`;
function injectFBBtn(article) { function injectFBBtn(article) {
if (article.dataset.tldrDone) return; 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'; article.dataset.tldrDone = '1';
const text = extractFBText(article); 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() { function scanFB() {
document.querySelectorAll('div[role="article"]').forEach(injectFBBtn); clearTimeout(scanTimer);
scanTimer = setTimeout(() => {
document.querySelectorAll('div[role="article"]').forEach(injectFBBtn);
}, 600);
} }
// ── General articles / pages ────────────────────────────────────────────── // ── General articles / pages ──────────────────────────────────────────────