Fix tracker action row wrapping and dedupe AI/action containers

This commit is contained in:
2026-02-26 01:03:15 +01:00
parent 05a94dae1c
commit 7ac681b089

View File

@@ -854,20 +854,39 @@ function ensureTrackerActionsContainer(container) {
return null; return null;
} }
let actionsContainer = container.querySelector('.fb-tracker-actions-end'); const existingContainers = Array.from(container.querySelectorAll('.fb-tracker-actions-end'))
.filter((candidate) => candidate && candidate.closest('.fb-tracker-ui') === container);
let actionsContainer = existingContainers.length > 0 ? existingContainers[0] : null;
if (actionsContainer && actionsContainer.isConnected) { if (actionsContainer && actionsContainer.isConnected) {
return actionsContainer; existingContainers.slice(1).forEach((duplicate) => {
while (duplicate.firstChild) {
actionsContainer.appendChild(duplicate.firstChild);
}
duplicate.remove();
});
} else {
actionsContainer = null;
} }
if (!actionsContainer) {
actionsContainer = document.createElement('div'); actionsContainer = document.createElement('div');
actionsContainer.className = 'fb-tracker-actions-end'; actionsContainer.className = 'fb-tracker-actions-end';
container.appendChild(actionsContainer);
}
actionsContainer.style.cssText = ` actionsContainer.style.cssText = `
margin-left: auto; margin-left: auto;
display: inline-flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-end;
gap: 8px; gap: 8px;
flex-wrap: wrap;
min-width: 0;
max-width: 100%;
flex: 1 1 auto;
`; `;
container.appendChild(actionsContainer);
return actionsContainer; return actionsContainer;
} }
@@ -6246,6 +6265,11 @@ async function addAICommentButton(container, postElement) {
return; return;
} }
const existingWrapper = actionsContainer.querySelector('.fb-tracker-ai-wrapper');
if (existingWrapper && existingWrapper.isConnected) {
return;
}
const encodedPostUrl = container && container.getAttribute('data-post-url') const encodedPostUrl = container && container.getAttribute('data-post-url')
? container.getAttribute('data-post-url') ? container.getAttribute('data-post-url')
: null; : null;
@@ -6261,6 +6285,8 @@ async function addAICommentButton(container, postElement) {
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
transition: transform 0.2s ease, box-shadow 0.2s ease; transition: transform 0.2s ease, box-shadow 0.2s ease;
flex: 0 1 auto;
max-width: 100%;
`; `;
const button = document.createElement('button'); const button = document.createElement('button');