Enhance popup preview with base URL and AI functionality support
This commit is contained in:
parent
4fa252f73d
commit
b1ea03fe21
1 changed files with 19 additions and 2 deletions
21
src/ui.js
21
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('<head>')
|
||||
? translatedText.replace('<head>', `<head><base href="${baseUrl}">`)
|
||||
: `<html><head><base href="${baseUrl}"></head><body>${translatedText}</body></html>`;
|
||||
|
||||
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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue