Spaces:
Running
Running
File size: 17,623 Bytes
84e1dd3 cfa7476 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Pro Suite - Text Translator</title>
<link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#0f172a">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/localforage/1.10.0/localforage.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="overlay" id="overlay"></div>
<div class="topbar">
<div class="menuBtn" onclick="toggleSidebar()">☰</div>
<div class="appTitle">AI Pro Suite</div>
</div>
<div class="apiTracker">
<div>⏱️ Reset: <span id="apiTimer" class="api-val timer">60s</span></div>
<div>🖼️ Vis: <span id="apiVision" class="api-val vision">0</span>/20</div>
<div>📝 Txt: <span id="apiText" class="api-val text">0</span>/20</div>
</div>
<div id="ttsPlayer">
<div class="ttsIndicator">🔊 Reading</div>
<button class="ttsBtn" id="ttsPlayBtn">⏸️</button>
<button class="ttsBtn" id="ttsStopBtn">⏹️</button>
<button class="ttsBtn" id="ttsCloseBtn">✖️</button>
</div>
<div class="sidebar" id="sidebar" style="overflow-y:auto;">
<button class="sidebar-close-btn" onclick="toggleSidebar()">✖ Close Menu</button>
<button onclick="window.location.href='index.html'">🏠 Dashboard</button>
<button onclick="window.location.href='lens.html'">✨ Lens Studio</button>
<button onclick="window.location.href='books.html'">📚 Book Deep Study</button>
<button onclick="window.location.href='maths.html'">🧮 Math Solver</button>
<button onclick="window.location.href='search.html'">🔎 Deep Search</button>
<button onclick="window.location.href='downloader.html'">📥 Video Downloader</button>
<button onclick="window.location.href='board.html'">📋 Whiteboard</button>
<button onclick="window.location.href='clone.html'">📑 Website Cloner</button>
<button onclick="window.location.href='runhtml.html'">🌐 Write HTML</button>
<button onclick="window.location.href='youtube.html'">▶️ YouTube Search</button>
<button onclick="window.location.href='managequiz.html'">⚙️ Manage Quiz</button>
<button onclick="window.location.href='tutor.html'">👨🏫 AI Tutor</button>
<button onclick="window.location.href='quiz.html'">📝 Take a Quiz!</button>
<button onclick="window.location.href='book_quiz.html'">📝 Take a Book Quiz!</button>
<button onclick="window.location.href='tables.html'">🔢 Maths Table</button>
<button onclick="window.location.href='coding.html'">💻 AI Coding</button>
<button onclick="window.location.href='chess.html'">♟️ Chess AI</button>
<button onclick="window.location.href='translator.html'" style="border-left: 4px solid var(--primary); color: var(--primary); background: var(--border-light);">🎙️ Text Translator</button>
<button onclick="window.location.href='image.html'">🖼️ Image Translator</button>
<button onclick="window.location.href='create.html'">🎨 Image Creator</button>
<button onclick="window.location.href='qa.html'">📚 Document Q&A</button>
<button onclick="window.location.href='history.html'">🕒 History & Downloads</button>
<button onclick="window.location.href='storage.html'">📂 Storage</button>
<button onclick="window.location.href='hub.html'">🛰️ HF Command Center</button>
<button onclick="window.location.href='live.html'">🗣️ Gemini Live</button>
</div>
<style>
/* This page had almost no dedicated styling before - mic button and voice
header were relying on bare browser defaults. Scoped to this page only. */
#translatorPage .voiceHeader { display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
#translatorPage .micBtn {
width:52px; height:52px; border-radius:50%; border:none; cursor:pointer; font-size:20px;
background:linear-gradient(135deg, var(--primary), var(--secondary)); color:#fff;
box-shadow:0 6px 16px var(--primary-glow); transition:transform .2s ease, box-shadow .2s ease;
display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
#translatorPage .micBtn:hover { transform:scale(1.07); }
#translatorPage .micBtn.recording { background:linear-gradient(135deg, #ef4444, #b91c1c); animation:pulse 0.8s infinite alternate; box-shadow:0 6px 20px rgba(239,68,68,0.6); }
#translatorPage .recordingHint { font-size:12px; color:#ef4444; font-weight:700; text-align:center; margin:-6px 0 12px; display:none; align-items:center; justify-content:center; gap:6px; }
#translatorPage .recordingHint.active { display:flex; }
#translatorPage .charCount { font-size:11px; color:var(--text-muted); text-align:right; margin-top:-8px; margin-bottom:10px; }
#translatorPage select.standard, #translatorPage select { width:100%; margin-bottom:14px; }
#translatorPage #convertBtn { display:flex; align-items:center; justify-content:center; gap:8px; }
#translatorPage #convertBtn:disabled { opacity:0.75; cursor:not-allowed; }
#translatorPage .hardWordsCard { background:rgba(168,85,247,0.08); border:1px solid rgba(168,85,247,0.3); border-radius:16px; padding:14px 16px; margin-top:16px; display:none; }
#translatorPage .hardWordsCard .cardTitle { color:#a855f7; margin-bottom:8px; }
#translatorPage #hardWords { font-size:14px; line-height:1.8; }
</style>
<div class="page active" id="translatorPage">
<div class="card" style="background:linear-gradient(135deg,#f59e0b,#d97706); border:none; text-align:center;">
<h1 style="font-size: 24px;">🎙️ Voice & Text Translator</h1>
<p style="font-size: 14px; opacity: 0.9;">Speak or type to instantly translate.</p>
</div>
<div class="card">
<div class="voiceHeader">
<div><div class="cardTitle" style="margin-bottom:0;">Input Text</div></div>
<button class="micBtn" id="micBtn" onclick="toggleRecording()" title="Speak your text">🎤</button>
</div>
<div class="recordingHint" id="recordingHint">🔴 Listening... tap the mic again to stop</div>
<select id="voiceSourceLang" style="margin-bottom: 10px;">
<option value="hi-IN">Speak in: Hindi</option>
<option value="en-US">Speak in: English</option>
</select>
<textarea class="standard" id="inputText" placeholder="Speak into the mic or type your text here..." oninput="document.getElementById('inputCharCount').innerText = this.value.length + ' characters'"></textarea>
<div class="charCount" id="inputCharCount">0 characters</div>
<div class="cardTitle" style="margin-top: 15px;">Translate Into:</div>
<select id="targetLang">
<option>Hindi</option>
<option>English</option>
<option>French</option>
<option>Spanish</option>
<option>German</option>
<option>Japanese</option>
</select>
<button class="btn blue" id="convertBtn" onclick="runTranslation()">🌍 Convert</button>
<div class="cardTitle" style="margin-top: 20px;">Translation Output:</div>
<div class="status" id="translatedTextStatus" style="display:none; margin-bottom:10px;"></div>
<div class="outputBox" id="translatedText" style="min-height: 100px;">Translation will appear here...</div>
<div class="hardWordsCard" id="hardWordsCard">
<div class="cardTitle">📖 Hard Words from Original Text</div>
<div id="hardWords"></div>
</div>
</div>
</div>
<script>
// 🎤 Voice input - was completely non-functional before (called but never defined).
let __translatorRecognition = null;
let __translatorRecording = false;
function toggleRecording() {
const micBtn = document.getElementById('micBtn');
const hint = document.getElementById('recordingHint');
const SpeechRecognitionAPI = window.SpeechRecognition || window.webkitSpeechRecognition;
if (!SpeechRecognitionAPI) {
if (typeof showToast === 'function') showToast("🎤 Voice input isn't supported in this browser. Try Chrome.");
else alert("Voice input isn't supported in this browser. Try Chrome.");
return;
}
if (__translatorRecording) {
__translatorRecognition.stop();
return;
}
const inputBox = document.getElementById('inputText');
const baseText = inputBox.value.trim() ? inputBox.value.trim() + ' ' : '';
__translatorRecognition = new SpeechRecognitionAPI();
__translatorRecognition.lang = document.getElementById('voiceSourceLang').value || 'en-US';
__translatorRecognition.interimResults = true;
__translatorRecognition.continuous = true;
__translatorRecognition.onstart = () => {
__translatorRecording = true;
micBtn.classList.add('recording');
micBtn.innerText = '⏹️';
if (hint) hint.classList.add('active');
};
__translatorRecognition.onresult = (event) => {
let interim = '', final = '';
for (let i = event.resultIndex; i < event.results.length; i++) {
if (event.results[i].isFinal) final += event.results[i][0].transcript;
else interim += event.results[i][0].transcript;
}
inputBox.value = baseText + final + interim;
document.getElementById('inputCharCount').innerText = inputBox.value.length + ' characters';
};
__translatorRecognition.onerror = (event) => {
console.error('Speech recognition error:', event.error);
if (event.error === 'not-allowed' && typeof showToast === 'function') showToast("🎤 Microphone access was blocked.");
};
__translatorRecognition.onend = () => {
__translatorRecording = false;
micBtn.classList.remove('recording');
micBtn.innerText = '🎤';
if (hint) hint.classList.remove('active');
};
__translatorRecognition.start();
}
// 🔊 Thin wrapper so any leftover callers of speakText keep working via the shared engine.
function speakText(elementId) {
if (typeof speakAndHighlight === 'function') speakAndHighlight(elementId);
}
document.addEventListener("DOMContentLoaded", () => {
const urlParams = new URLSearchParams(window.location.search);
const restoreId = urlParams.get('restore');
if (!restoreId) return;
// Wait 800ms to guarantee the page, CSS, and animations are 100% finished loading
setTimeout(() => {
// Automatically hunt down the chat box or text area on the page
let container = document.querySelector('.chat-scroll-area') ||
document.getElementById('chatHistory') ||
document.getElementById('searchChatHistory') ||
document.getElementById('qaAnswerBox') ||
document.getElementById('translatedText');
if (!container) return;
const forceInjectData = (historyData) => {
let item = historyData.find(i => i.id == restoreId);
if (!item) return;
// 🛑 SCENARIO 1: It's a Chat Interface (Search, Image)
if (item.interactions && item.interactions.length > 0 && container.classList.contains('chat-scroll-area')) {
container.innerHTML = ''; // Wipe the empty screen
item.interactions.forEach((inter, index) => {
let imgHtml = inter.image ? `<img src="${inter.image}" class="bubble-img" style="max-width:100%; border-radius:16px; margin-bottom:15px; border: 2px solid var(--border-light); box-shadow: var(--glass-shadow);">` : '';
let textId = `restored_text_${index}`;
container.insertAdjacentHTML('beforeend', `
<div class="chat-msg chat-user" style="animation: slideInUp 0.5s ease-out;">
<div class="bubble" style="background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; border-bottom-right-radius: 6px; box-shadow: 0 8px 25px var(--primary-glow);">
${imgHtml}
<div>${inter.question.replace(/\n/g, '<br>')}</div>
</div>
</div>
<div class="chat-msg chat-ai" style="animation: bounceInBubble 0.6s ease-out;">
<div class="bubble" style="background: var(--bg-surface); border: 1px solid var(--border-light); border-bottom-left-radius: 6px; box-shadow: var(--glass-shadow); display: flex; flex-direction: column;">
<div id="${textId}" style="margin-top:0; width:100%; overflow-x:auto;">${inter.answer.replace(/\n/g, '<br>')}</div>
<div class="action-buttons-container" style="display:flex; flex-wrap:wrap; gap:10px; margin-top:25px; padding-top:15px; border-top:1px solid var(--border-light); width:100%;">
<button class="btn green" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; cursor: pointer; flex: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.05);" onclick="speakAndHighlight('${textId}')">🔊 Listen</button>
<button class="btn" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; cursor: pointer; flex: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.05);" onclick="copyToClipboard('${textId}')">📋 Copy</button>
</div>
</div>
</div>
`);
});
// Force the window to scroll to the newly injected text
setTimeout(() => { container.scrollTop = container.scrollHeight; }, 100);
if (typeof showToast === 'function') showToast("🔄 Search Restored Successfully!");
}
// 🛑 SCENARIO 2: It's a Text Box Interface (Translator, Q&A)
else {
let textId = `restored_text_box`;
let ansText = item.interactions ? item.interactions[0].answer : item.answer;
container.innerHTML = `
<div id="${textId}" style="margin-top:0;">${ansText.replace(/\n/g, '<br>')}</div>
<div style="display:flex; flex-wrap:wrap; gap:10px; margin-top:25px; padding-top:15px; border-top:1px solid var(--border-light);">
<button class="btn green" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; flex: 1;" onclick="speakAndHighlight('${textId}')">🔊 Listen</button>
<button class="btn" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; flex: 1;" onclick="copyToClipboard('${textId}')">📋 Copy</button>
</div>
`;
// Refill the input text box too
if (document.getElementById('inputText')) document.getElementById('inputText').value = item.question || "";
if (typeof showToast === 'function') showToast("🔄 Document Restored Successfully!");
}
// Safely render any Math/Physics equations (LaTeX)
if (window.MathJax) {
MathJax.typesetPromise([container]).catch(e => console.log(e));
}
};
// Safely fetch from your LocalForage database, fallback to LocalStorage
if (typeof localforage !== 'undefined') {
localforage.getItem('aiHistory').then(data => {
if (data && data.length > 0) forceInjectData(data);
else forceInjectData(JSON.parse(localStorage.getItem('aiHistory') || '[]'));
}).catch(() => forceInjectData(JSON.parse(localStorage.getItem('aiHistory') || '[]')));
} else {
forceInjectData(JSON.parse(localStorage.getItem('aiHistory') || '[]'));
}
}, 800); // 👈 THIS 800ms DELAY IS THE MAGIC FIX. IT WAITS FOR EVERYTHING TO BE READY.
});
</script>
<script src="ui-controls.js" defer></script>
<script src="main.js" defer></script>
</body>
</html> |