From 2824392149e49200f0ad3ea973b6d3d6b39ad567 Mon Sep 17 00:00:00 2001 From: Meik Date: Thu, 26 Feb 2026 00:09:52 +0100 Subject: [PATCH] Fix comment anchor detection for tracker placement --- extension/content.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/extension/content.js b/extension/content.js index b2e4183..9de3491 100644 --- a/extension/content.js +++ b/extension/content.js @@ -272,8 +272,6 @@ function findCommentSectionAnchorInPost(postElement, actionAnchor = null) { '[aria-label*="most relevant" i]', '[aria-label*="neueste" i]', '[aria-label*="newest" i]', - '[aria-label*="kommentare" i]', - '[aria-label*="comments" i]', '[aria-roledescription*="kommentar" i]', '[aria-roledescription*="comment" i]', '[data-testid*="comment" i]', @@ -287,7 +285,7 @@ function findCommentSectionAnchorInPost(postElement, actionAnchor = null) { const anchors = new Set(); postElement.querySelectorAll(selectors.join(', ')).forEach((candidate) => { - if (!candidate || candidate.closest('.fb-tracker-ui')) { + if (!candidate || candidate.closest('.fb-tracker-ui') || !isElementVisible(candidate)) { return; } @@ -299,11 +297,17 @@ function findCommentSectionAnchorInPost(postElement, actionAnchor = null) { || candidate; } - const anchor = getTopLevelAnchorWithinPost(postElement, anchorSeed); - if (!anchor || anchor === actionAnchor) { + let anchor = getTopLevelAnchorWithinPost(postElement, anchorSeed); + if (anchor === actionAnchor) { + anchor = anchorSeed; + } + + if (!anchor || anchor === actionAnchor || !anchor.parentElement) { return; } - if (actionAnchor && !isNodeAfter(anchor, actionAnchor)) { + + const anchorIsInsideAction = Boolean(actionAnchor && actionAnchor.contains(anchor)); + if (actionAnchor && !anchorIsInsideAction && !isNodeAfter(anchor, actionAnchor)) { return; }