From b1ea03fe21aeca0b0fdfe90b956d15761498db46 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Tue, 1 Jul 2025 16:51:45 -0400 Subject: [PATCH] Enhance popup preview with base URL and AI functionality support --- src/ui.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ui.js b/src/ui.js index 21384f8..a0c56ea 100644 --- a/src/ui.js +++ b/src/ui.js @@ -1721,9 +1721,26 @@ export function openTranslateModal() { const openPreview = () => { const previewWindow = window.open('', '_blank', 'width=1200,height=800,scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no,status=no'); if (previewWindow) { - previewWindow.document.write(translatedText); + // Inject base URL for relative resources to work + const baseUrl = window.location.origin + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1); + const htmlWithBase = translatedText.includes('') + ? translatedText.replace('', ``) + : `${translatedText}`; + + previewWindow.document.write(htmlWithBase); previewWindow.document.close(); - previewWindow.document.title = `Translation Preview (${targetLanguageName})`; + previewWindow.document.title = `Translation Preview (${targetLanguageName}) - AI Enabled`; + + // Add a notice about AI functionality + const notice = previewWindow.document.createElement('div'); + notice.style.cssText = 'position: fixed; top: 10px; right: 10px; background: #4CAF50; color: white; padding: 8px 12px; border-radius: 4px; font-size: 12px; z-index: 10000; box-shadow: 0 2px 8px rgba(0,0,0,0.2);'; + notice.textContent = `🤖 AI features should work in ${targetLanguageName}!`; + previewWindow.document.body.appendChild(notice); + + // Auto-hide notice after 5 seconds + setTimeout(() => { + if (notice.parentNode) notice.parentNode.removeChild(notice); + }, 5000); } else { alert('Please allow popups for preview window'); }