From 7ac681b0899e7d1195e755cb6daadd38afc3d300 Mon Sep 17 00:00:00 2001 From: Meik Date: Thu, 26 Feb 2026 01:03:15 +0100 Subject: [PATCH] Fix tracker action row wrapping and dedupe AI/action containers --- extension/content.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/extension/content.js b/extension/content.js index 899688f..0bfdbeb 100644 --- a/extension/content.js +++ b/extension/content.js @@ -854,20 +854,39 @@ function ensureTrackerActionsContainer(container) { 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) { - 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.className = 'fb-tracker-actions-end'; + container.appendChild(actionsContainer); } - actionsContainer = document.createElement('div'); - actionsContainer.className = 'fb-tracker-actions-end'; actionsContainer.style.cssText = ` margin-left: auto; - display: inline-flex; + display: flex; align-items: center; + justify-content: flex-end; gap: 8px; + flex-wrap: wrap; + min-width: 0; + max-width: 100%; + flex: 1 1 auto; `; - container.appendChild(actionsContainer); + return actionsContainer; } @@ -6246,6 +6265,11 @@ async function addAICommentButton(container, postElement) { return; } + const existingWrapper = actionsContainer.querySelector('.fb-tracker-ai-wrapper'); + if (existingWrapper && existingWrapper.isConnected) { + return; + } + const encodedPostUrl = container && container.getAttribute('data-post-url') ? container.getAttribute('data-post-url') : null; @@ -6261,6 +6285,8 @@ async function addAICommentButton(container, postElement) { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); transition: transform 0.2s ease, box-shadow 0.2s ease; + flex: 0 1 auto; + max-width: 100%; `; const button = document.createElement('button');