Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const uploadBtn = document.getElementById('uploadBtn');
+ const fileInput = document.getElementById('fileInput');
+ const originalContent = document.getElementById('originalContent');
+ const translatedContent = document.getElementById('translatedContent');
+
+ uploadBtn.addEventListener('click', () => {
+ fileInput.click();
+ });
+
+ fileInput.addEventListener('change', async (e) => {
+ const file = e.target.files[0];
+ if (file && file.type === 'application/pdf') {
+ try {
+ // In a real implementation, we would:
+ // 1. Send the PDF to a server
+ // 2. Process it to extract text
+ // 3. Translate the text
+ // 4. Return both versions
+
+ // For demo purposes, we'll just show a sample
+ originalContent.textContent = "This is a sample original text extracted from the PDF.\n\nIt would contain multiple paragraphs and maintain the formatting of the original document.";
+
+ translatedContent.textContent = "这是从PDF中提取的示例原文。\n\n它将包含多个段落并保持原始文档的格式。";
+
+ // Hide placeholders
+ document.querySelectorAll('.placeholder').forEach(p => p.style.display = 'none');
+ } catch (error) {
+ alert('Error processing PDF. Please try again.');
+ }
+ } else {
+ alert('Please select a valid PDF file.');
+ }
+ });
+
+ // Sync scroll between viewers
+ const viewers = document.querySelectorAll('.viewer');
+ viewers.forEach(viewer => {
+ viewer.addEventListener('scroll', (e) => {
+ const scrollPercentage = e.target.scrollTop / (e.target.scrollHeight - e.target.clientHeight);
+ viewers.forEach(otherViewer => {
+ if (otherViewer !== e.target) {
+ otherViewer.scrollTop = scrollPercentage * (otherViewer.scrollHeight - otherViewer.clientHeight);
+ }
+ });
+ });
+ });
+ });