Avoid interactive parent anchors and enforce clickable tracker layer

This commit is contained in:
2026-02-26 00:59:04 +01:00
parent 51dc2c191c
commit 05a94dae1c

View File

@@ -610,14 +610,64 @@ function createTrackerInsertionMarker() {
return marker; return marker;
} }
function isInteractiveContainer(element) {
return Boolean(
element
&& element.matches
&& element.matches('a, button, [role="button"]')
);
}
function normalizeTrackerInsertionAnchor(postElement, anchor) {
if (!postElement || !anchor || !anchor.isConnected || !postElement.contains(anchor)) {
return null;
}
let current = anchor;
while (current && current !== postElement) {
const parent = current.parentElement;
if (!parent || !postElement.contains(parent)) {
break;
}
if (isInteractiveContainer(current) || isInteractiveContainer(parent)) {
current = parent;
continue;
}
break;
}
return current;
}
function insertMarkerBeforeAnchor(postElement, marker, anchor) {
const target = normalizeTrackerInsertionAnchor(postElement, anchor);
if (!target || !target.parentElement) {
return false;
}
target.parentElement.insertBefore(marker, target);
return true;
}
function insertMarkerAfterAnchor(postElement, marker, anchor) {
const target = normalizeTrackerInsertionAnchor(postElement, anchor);
if (!target || !target.parentElement) {
return false;
}
target.parentElement.insertBefore(marker, target.nextSibling);
return true;
}
function positionTrackerInsertionMarker(postElement, marker, buttonBar, postNum = '?') { function positionTrackerInsertionMarker(postElement, marker, buttonBar, postNum = '?') {
if (!postElement || !marker) { if (!postElement || !marker) {
return false; return false;
} }
const commentComposerAnchor = findCommentComposerAnchorInPost(postElement); const commentComposerAnchor = findCommentComposerAnchorInPost(postElement);
if (commentComposerAnchor && commentComposerAnchor.parentElement) { if (commentComposerAnchor && insertMarkerBeforeAnchor(postElement, marker, commentComposerAnchor)) {
commentComposerAnchor.parentElement.insertBefore(marker, commentComposerAnchor);
setTrackerInsertionMarkerLocked(marker, true); setTrackerInsertionMarkerLocked(marker, true);
console.log('[FB Tracker] Post #' + postNum + ' - Marker inserted before comment composer'); console.log('[FB Tracker] Post #' + postNum + ' - Marker inserted before comment composer');
return true; return true;
@@ -627,21 +677,18 @@ function positionTrackerInsertionMarker(postElement, marker, buttonBar, postNum
const actionAnchor = getDirectActionAnchorInPost(postElement, resolvedButtonBar); const actionAnchor = getDirectActionAnchorInPost(postElement, resolvedButtonBar);
const commentBoundary = findCommentBoundaryAnchorInPost(postElement, actionAnchor); const commentBoundary = findCommentBoundaryAnchorInPost(postElement, actionAnchor);
if (commentBoundary && commentBoundary.parentElement) { if (commentBoundary && insertMarkerBeforeAnchor(postElement, marker, commentBoundary)) {
commentBoundary.parentElement.insertBefore(marker, commentBoundary);
setTrackerInsertionMarkerLocked(marker, true); setTrackerInsertionMarkerLocked(marker, true);
console.log('[FB Tracker] Post #' + postNum + ' - Marker inserted before comment boundary'); console.log('[FB Tracker] Post #' + postNum + ' - Marker inserted before comment boundary');
return true; return true;
} }
if (actionAnchor && actionAnchor.parentElement) { if (actionAnchor && insertMarkerAfterAnchor(postElement, marker, actionAnchor)) {
actionAnchor.parentElement.insertBefore(marker, actionAnchor.nextSibling);
setTrackerInsertionMarkerLocked(marker, true); setTrackerInsertionMarkerLocked(marker, true);
return true; return true;
} }
if (resolvedButtonBar && resolvedButtonBar.parentElement && postElement.contains(resolvedButtonBar.parentElement)) { if (resolvedButtonBar && insertMarkerAfterAnchor(postElement, marker, resolvedButtonBar)) {
resolvedButtonBar.parentElement.insertBefore(marker, resolvedButtonBar.nextSibling);
setTrackerInsertionMarkerLocked(marker, true); setTrackerInsertionMarkerLocked(marker, true);
return true; return true;
} }
@@ -663,6 +710,10 @@ function isTrackerInsertionMarkerPlacementValid(postElement, marker, buttonBar)
return false; return false;
} }
if (marker.closest('a, button, [role="button"]')) {
return false;
}
const commentBoundary = findCommentBoundaryAnchorInPost(postElement); const commentBoundary = findCommentBoundaryAnchorInPost(postElement);
if (commentBoundary && isNodeAfter(marker, commentBoundary)) { if (commentBoundary && isNodeAfter(marker, commentBoundary)) {
@@ -3680,8 +3731,12 @@ async function createTrackerUI(postElement, buttonBar, postNum = '?', options =
align-items: center; align-items: center;
gap: 8px; gap: 8px;
row-gap: 6px; row-gap: 6px;
flex: 0 0 100%;
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
position: relative;
z-index: 5;
pointer-events: auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
font-size: 13px; font-size: 13px;
`; `;