diff --git a/src/ui.js b/src/ui.js index 152a54f..4033406 100644 --- a/src/ui.js +++ b/src/ui.js @@ -328,12 +328,14 @@ export function createFloatingAIButton() { const hasPicoCSS = document.querySelector('link[href*="pico"]') !== null; const cssFile = hasPicoCSS ? 'uncloseai-modal-pico.css' : 'uncloseai-modal-builtin.css'; + let cssLoaded = false; if (!document.querySelector(`link[href*="${cssFile}"]`)) { const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = `https://uncloseai.com/src/${cssFile}`; document.head.appendChild(link); console.log(`uncloseai.js: Loaded ${cssFile} for floating button styles.`); + cssLoaded = true; } // Remove any existing floating button first @@ -388,8 +390,16 @@ export function createFloatingAIButton() { // Set up self-contained click handler setupFloatingButtonHandler(floatingButton); - document.body.appendChild(floatingButton); - console.log("uncloseai.js: Appended floating button to document.body."); + // If we just loaded CSS, wait a bit before showing button + if (cssLoaded) { + setTimeout(() => { + document.body.appendChild(floatingButton); + console.log("uncloseai.js: Appended floating button to document.body after CSS load delay."); + }, 100); + } else { + document.body.appendChild(floatingButton); + console.log("uncloseai.js: Appended floating button to document.body."); + } } // Set up click handler for floating button (self-contained)