Fix comment anchor detection for tracker placement

This commit is contained in:
2026-02-26 00:09:52 +01:00
parent 233355319e
commit 2824392149

View File

@@ -272,8 +272,6 @@ function findCommentSectionAnchorInPost(postElement, actionAnchor = null) {
'[aria-label*="most relevant" i]', '[aria-label*="most relevant" i]',
'[aria-label*="neueste" i]', '[aria-label*="neueste" i]',
'[aria-label*="newest" i]', '[aria-label*="newest" i]',
'[aria-label*="kommentare" i]',
'[aria-label*="comments" i]',
'[aria-roledescription*="kommentar" i]', '[aria-roledescription*="kommentar" i]',
'[aria-roledescription*="comment" i]', '[aria-roledescription*="comment" i]',
'[data-testid*="comment" i]', '[data-testid*="comment" i]',
@@ -287,7 +285,7 @@ function findCommentSectionAnchorInPost(postElement, actionAnchor = null) {
const anchors = new Set(); const anchors = new Set();
postElement.querySelectorAll(selectors.join(', ')).forEach((candidate) => { postElement.querySelectorAll(selectors.join(', ')).forEach((candidate) => {
if (!candidate || candidate.closest('.fb-tracker-ui')) { if (!candidate || candidate.closest('.fb-tracker-ui') || !isElementVisible(candidate)) {
return; return;
} }
@@ -299,11 +297,17 @@ function findCommentSectionAnchorInPost(postElement, actionAnchor = null) {
|| candidate; || candidate;
} }
const anchor = getTopLevelAnchorWithinPost(postElement, anchorSeed); let anchor = getTopLevelAnchorWithinPost(postElement, anchorSeed);
if (!anchor || anchor === actionAnchor) { if (anchor === actionAnchor) {
anchor = anchorSeed;
}
if (!anchor || anchor === actionAnchor || !anchor.parentElement) {
return; return;
} }
if (actionAnchor && !isNodeAfter(anchor, actionAnchor)) {
const anchorIsInsideAction = Boolean(actionAnchor && actionAnchor.contains(anchor));
if (actionAnchor && !anchorIsInsideAction && !isNodeAfter(anchor, actionAnchor)) {
return; return;
} }