Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const sourceText = document.getElementById('source-text');
+ const translatedText = document.getElementById('translated-text');
+ const translateBtn = document.getElementById('translate-btn');
+ const copyBtn = document.getElementById('copy-btn');
+
+ // Smooth scroll for navigation links
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
+ anchor.addEventListener('click', function (e) {
+ e.preventDefault();
+ document.querySelector(this.getAttribute('href')).scrollIntoView({
+ behavior: 'smooth'
+ });
+ });
+ });
+
+ // Translation button animation
+ translateBtn.addEventListener('click', async () => {
+ if (!sourceText.value.trim()) {
+ alert('Please enter some text to translate');
+ return;
+ }
+
+ translateBtn.disabled = true;
+ translateBtn.innerHTML = 'Translating...';
+
+ try {
+ // Simulate translation API call with timeout
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+ // This is where you would normally make an API call to a translation service
+ // For demo purposes, we'll just append "翻译" to each line
+ const translation = sourceText.value.split('\n')
+ .map(line => line.trim() ? `${line} 翻译` : '')
+ .join('\n');
+
+ translatedText.value = translation;
+ } catch (error) {
+ alert('Translation failed. Please try again.');
+ } finally {
+ translateBtn.disabled = false;
+ translateBtn.innerHTML = 'Translate→';
+ }
+ });
+
+ // Copy button functionality
+ copyBtn.addEventListener('click', () => {
+ if (!translatedText.value) {
+ alert('No translation to copy');
+ return;
+ }
+
+ translatedText.select();
+ document.execCommand('copy');
+
+ const originalText = copyBtn.textContent;
+ copyBtn.textContent = 'Copied!';
+ setTimeout(() => {
+ copyBtn.textContent = originalText;
+ }, 2000);
+ });
+
+ // Auto-resize textareas
+ const autoResize = (element) => {
+ element.style.height = 'auto';
+ element.style.height = element.scrollHeight + 'px';
+ };
+
+ sourceText.addEventListener('input', () => autoResize(sourceText));
+ translatedText.addEventListener('input', () => autoResize(translatedText));
+ });