Prevent tracker realign from closing open dropdowns and datepicker
This commit is contained in:
@@ -939,15 +939,69 @@ function insertTrackerAtMarker(marker, trackerElement) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
trackerElement.parentElement === marker.parentElement
|
||||||
|
&& trackerElement.previousElementSibling === marker
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
marker.parentElement.insertBefore(trackerElement, marker.nextSibling);
|
marker.parentElement.insertBefore(trackerElement, marker.nextSibling);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TRACKER_INTERACTION_GRACE_MS = 2200;
|
||||||
|
|
||||||
|
function markTrackerInteraction(trackerElement) {
|
||||||
|
if (!trackerElement || !trackerElement.dataset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
trackerElement.dataset.realignBlockedUntil = String(Date.now() + TRACKER_INTERACTION_GRACE_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTrackerInteractionActive(trackerElement) {
|
||||||
|
if (!trackerElement || !trackerElement.isConnected) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blockedUntil = parseInt(trackerElement.dataset.realignBlockedUntil || '0', 10);
|
||||||
|
if (!Number.isNaN(blockedUntil) && blockedUntil > Date.now()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trackerElement.querySelector('.fb-tracker-ai-wrapper--open')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeElement = document.activeElement;
|
||||||
|
return Boolean(activeElement && trackerElement.contains(activeElement));
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindTrackerInteractionGuard(trackerElement) {
|
||||||
|
if (!trackerElement || trackerElement.dataset.realignGuardBound === '1') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
trackerElement.dataset.realignGuardBound = '1';
|
||||||
|
|
||||||
|
const bumpInteraction = () => markTrackerInteraction(trackerElement);
|
||||||
|
trackerElement.addEventListener('focusin', bumpInteraction, true);
|
||||||
|
trackerElement.addEventListener('pointerdown', bumpInteraction, true);
|
||||||
|
trackerElement.addEventListener('mousedown', bumpInteraction, true);
|
||||||
|
trackerElement.addEventListener('click', bumpInteraction, true);
|
||||||
|
trackerElement.addEventListener('keydown', bumpInteraction, true);
|
||||||
|
}
|
||||||
|
|
||||||
function realignExistingTrackerUI(postElement, buttonBar, trackerElement, postNum = '?') {
|
function realignExistingTrackerUI(postElement, buttonBar, trackerElement, postNum = '?') {
|
||||||
if (!postElement || !trackerElement || !trackerElement.isConnected) {
|
if (!postElement || !trackerElement || !trackerElement.isConnected) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bindTrackerInteractionGuard(trackerElement);
|
||||||
|
if (isTrackerInteractionActive(trackerElement)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const marker = ensureTrackerInsertionMarker(postElement, buttonBar, postNum);
|
const marker = ensureTrackerInsertionMarker(postElement, buttonBar, postNum);
|
||||||
if (!marker) {
|
if (!marker) {
|
||||||
return false;
|
return false;
|
||||||
@@ -3938,6 +3992,7 @@ async function createTrackerUI(postElement, buttonBar, postNum = '?', options =
|
|||||||
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;
|
||||||
`;
|
`;
|
||||||
|
bindTrackerInteractionGuard(container);
|
||||||
|
|
||||||
// Check current status (check all URL candidates to avoid duplicates)
|
// Check current status (check all URL candidates to avoid duplicates)
|
||||||
const profileNumber = await getProfileNumber();
|
const profileNumber = await getProfileNumber();
|
||||||
|
|||||||
Reference in New Issue
Block a user