fix: skip comment articles, debounce MutationObserver to prevent RAM spike
This commit is contained in:
@@ -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 ──────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user