From 1b7597501ace165ec680dc6934864a102cd0da7f Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 9 Jul 2025 16:14:44 -0400 Subject: [PATCH] revert: restore original translateCurrentPage function The CSS refactoring broke translated page rendering. The original function was working correctly by translating the complete HTML document structure. Translated pages don't need modal CSS, just the original page styling. --- src/translation.js | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/src/translation.js b/src/translation.js index d5dde17..07fdf71 100644 --- a/src/translation.js +++ b/src/translation.js @@ -353,7 +353,7 @@ export function extractPageContent() { return documentClone.documentElement.outerHTML; } -// Translate current page content while preserving HTML structure +// Translate current page content export async function translateCurrentPage(targetLanguage) { const pageContent = extractPageContent(); @@ -361,41 +361,12 @@ export async function translateCurrentPage(targetLanguage) { throw new Error("Unable to extract meaningful content from this page."); } - // Create a temporary DOM to work with - const parser = new DOMParser(); - const doc = parser.parseFromString(pageContent, 'text/html'); - - // Get text content from body for translation - const bodyText = doc.body.textContent || doc.body.innerText || ''; - - if (!bodyText.trim()) { - throw new Error("No text content found to translate."); - } - // Limit content length to avoid overwhelming the AI - const maxLength = 50000; + const maxLength = 50000; // Much higher limit for complete page translation const contentToTranslate = - bodyText.length > maxLength - ? `${bodyText.substring(0, maxLength)}...` - : bodyText; + pageContent.length > maxLength + ? `${pageContent.substring(0, maxLength)}...` + : pageContent; - // Translate the text content - const translatedText = await translateText(contentToTranslate, targetLanguage); - - // Replace the body content with translated text while preserving structure - const translatedDoc = parser.parseFromString(pageContent, 'text/html'); - - // Create a simple structure with the translated text - translatedDoc.body.innerHTML = ` -
-

- ${translatedDoc.title || 'Translated Page'} (${targetLanguage.toUpperCase()}) -

-
- ${translatedText.replace(/\n/g, '
')} -
-
- `; - - return translatedDoc.documentElement.outerHTML; + return await translateText(contentToTranslate, targetLanguage); }