Anchor tracker before feedback section to avoid FB action row overlap
This commit is contained in:
@@ -418,6 +418,18 @@ function isCompactActionBarCandidate(postElement, candidate) {
|
|||||||
return hasInteractionButtons(candidate);
|
return hasInteractionButtons(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasMainPostContentSignal(node) {
|
||||||
|
if (!node || !node.querySelector) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean(
|
||||||
|
node.querySelector(
|
||||||
|
'[data-ad-preview*="message" i], [data-ad-comet-preview*="message" i], [data-ad-preview*="story" i], [data-ad-comet-preview*="story" i]'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeActionBarCandidate(postElement, candidate) {
|
function normalizeActionBarCandidate(postElement, candidate) {
|
||||||
if (!postElement || !candidate || !candidate.isConnected || !postElement.contains(candidate)) {
|
if (!postElement || !candidate || !candidate.isConnected || !postElement.contains(candidate)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -444,6 +456,55 @@ function normalizeActionBarCandidate(postElement, candidate) {
|
|||||||
return isReliableActionBarCandidate(postElement, candidate) ? candidate : null;
|
return isReliableActionBarCandidate(postElement, candidate) ? candidate : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findFeedbackSectionAnchor(postElement, actionAnchor = null) {
|
||||||
|
if (!postElement) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedAction = actionAnchor && postElement.contains(actionAnchor)
|
||||||
|
? actionAnchor
|
||||||
|
: resolveActionButtonBar(postElement, actionAnchor);
|
||||||
|
if (!resolvedAction || !resolvedAction.isConnected || !postElement.contains(resolvedAction)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const commentBoundary = findCommentBoundaryAnchorInPost(postElement, resolvedAction);
|
||||||
|
let candidate = resolvedAction;
|
||||||
|
let current = resolvedAction;
|
||||||
|
|
||||||
|
for (let depth = 0; depth < 12 && current && current !== postElement; depth++) {
|
||||||
|
const parent = current.parentElement;
|
||||||
|
if (!parent || !postElement.contains(parent) || parent === postElement) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasMainPostContentSignal(parent)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentLooksFeedback =
|
||||||
|
(commentBoundary && parent.contains(commentBoundary))
|
||||||
|
|| hasCommentComposerSignal(parent)
|
||||||
|
|| hasCommentSortSignal(parent)
|
||||||
|
|| hasCommentContentSignal(parent);
|
||||||
|
|
||||||
|
if (!parentLooksFeedback) {
|
||||||
|
// Keep climbing through transparent wrappers that only wrap this subtree.
|
||||||
|
if (parent.childElementCount === 1) {
|
||||||
|
candidate = parent;
|
||||||
|
current = parent;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
candidate = parent;
|
||||||
|
current = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
function isReliableActionBarCandidate(postElement, candidate) {
|
function isReliableActionBarCandidate(postElement, candidate) {
|
||||||
if (!postElement || !candidate || !candidate.isConnected || !postElement.contains(candidate)) {
|
if (!postElement || !candidate || !candidate.isConnected || !postElement.contains(candidate)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -772,6 +833,13 @@ function positionTrackerInsertionMarker(postElement, marker, buttonBar, postNum
|
|||||||
|
|
||||||
const resolvedButtonBar = resolveActionButtonBar(postElement, buttonBar);
|
const resolvedButtonBar = resolveActionButtonBar(postElement, buttonBar);
|
||||||
const actionAnchor = getDirectActionAnchorInPost(postElement, resolvedButtonBar);
|
const actionAnchor = getDirectActionAnchorInPost(postElement, resolvedButtonBar);
|
||||||
|
const feedbackAnchor = findFeedbackSectionAnchor(postElement, actionAnchor || resolvedButtonBar);
|
||||||
|
|
||||||
|
if (feedbackAnchor && insertMarkerBeforeAnchor(postElement, marker, feedbackAnchor)) {
|
||||||
|
setTrackerInsertionMarkerLocked(marker, true);
|
||||||
|
console.log('[FB Tracker] Post #' + postNum + ' - Marker inserted above feedback section');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (actionAnchor && insertMarkerBeforeAnchor(postElement, marker, actionAnchor)) {
|
if (actionAnchor && insertMarkerBeforeAnchor(postElement, marker, actionAnchor)) {
|
||||||
setTrackerInsertionMarkerLocked(marker, true);
|
setTrackerInsertionMarkerLocked(marker, true);
|
||||||
@@ -805,6 +873,18 @@ function isTrackerInsertionMarkerPlacementValid(postElement, marker, buttonBar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const actionAnchor = getDirectActionAnchorInPost(postElement, buttonBar);
|
const actionAnchor = getDirectActionAnchorInPost(postElement, buttonBar);
|
||||||
|
const feedbackAnchor = findFeedbackSectionAnchor(postElement, actionAnchor || buttonBar);
|
||||||
|
if (feedbackAnchor && isNodeAfter(marker, feedbackAnchor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (feedbackAnchor && marker.parentElement === feedbackAnchor.parentElement) {
|
||||||
|
const nextSibling = getNextNonTrackerSibling(marker);
|
||||||
|
if (nextSibling && nextSibling !== feedbackAnchor) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (actionAnchor) {
|
if (actionAnchor) {
|
||||||
if (isNodeAfter(marker, actionAnchor)) {
|
if (isNodeAfter(marker, actionAnchor)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user