Download app/static/index.html from Novard-ai/novard: direct link, hf CLI and curl.
- Browser
- Download file 51.9 kB
-
https://huggingface.co/spaces/Novard-ai/novard/resolve/main/app/static/index.html
- Command line
-
hf download hf://spaces/Novard-ai/novard/app/static/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Novard-ai/novard/resolve/main/app/static/index.html
51.9 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>SwitchLingo — Any video, your language</title> | |
| <meta name="description" content="SwitchLingo: AI that translates any video or link into your language with subtitles and voice-over in 100+ languages, and gets better from your corrections."> | |
| <link rel="canonical" href="https://switchlingo.ai/"> | |
| <meta property="og:title" content="SwitchLingo — Any video, your language"> | |
| <meta property="og:description" content="Paste a link, pick a language, hear it in your language. Subtitles and voice-over in 100+ languages."> | |
| <meta property="og:url" content="https://switchlingo.ai/"> | |
| <meta property="og:site_name" content="SwitchLingo"> | |
| <meta property="og:image" content="https://switchlingo.ai/demo-poster.jpg"> | |
| <meta name="twitter:card" content="summary_large_image"> | |
| <link rel="manifest" href="manifest.webmanifest"> | |
| <meta name="theme-color" content="#1d1628"> | |
| <link rel="apple-touch-icon" href="icon-192.png"> | |
| <link rel="icon" href="icon-192.png"> | |
| <link rel="preconnect" href="https://fonts.googleapis.com"> | |
| <link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600&family=Inter:wght@400;500;600&display=swap" rel="stylesheet"> | |
| <style> | |
| :root{--bg:#f6f3ee;--card:#fffdf9;--ink:#1d1b18;--muted:#6f6a62;--line:#e6e0d6;--accent:#b4532a;--accent-ink:#fff;--soft:#f2e7df;--ok:#2f7d4f;--bad:#b3261e} | |
| @media (prefers-color-scheme:dark){:root{--bg:#141311;--card:#1d1b18;--ink:#f1ece4;--muted:#a59f95;--line:#34302a;--accent:#e07a4a;--accent-ink:#1a0f09;--soft:#2a2420;--ok:#6cc08c;--bad:#f28b82}} | |
| *{box-sizing:border-box} | |
| body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 Inter,system-ui,sans-serif} | |
| .wrap{max-width:980px;margin:0 auto;padding:28px 16px 60px} | |
| header{display:flex;align-items:baseline;gap:14px;flex-wrap:wrap;margin-bottom:22px} | |
| h1{font:600 34px/1.1 Fraunces,Georgia,serif;margin:0;letter-spacing:-.5px} | |
| h1 span{color:var(--accent)} | |
| .tag{color:var(--muted)} | |
| .card{background:var(--card);border:1px solid var(--line);border-radius:16px;padding:20px;margin-bottom:18px} | |
| h2{font:600 19px Fraunces,Georgia,serif;margin:0 0 14px} | |
| .tabs{display:inline-flex;background:var(--soft);border-radius:10px;padding:3px;margin-bottom:12px} | |
| .tabs button{border:0;background:none;padding:7px 14px;border-radius:8px;font:500 14px Inter;color:var(--muted);cursor:pointer} | |
| .tabs button.on{background:var(--card);color:var(--ink);box-shadow:0 1px 2px rgba(0,0,0,.08)} | |
| input[type=text],input[type=url],select,textarea{width:100%;padding:11px 12px;border:1px solid var(--line);border-radius:10px;background:var(--bg);color:var(--ink);font:inherit} | |
| textarea{min-height:70px} | |
| .drop{border:2px dashed var(--line);border-radius:12px;padding:26px;text-align:center;color:var(--muted);cursor:pointer} | |
| .drop.over{border-color:var(--accent);background:var(--soft)} | |
| .drop.picked{border-style:solid;border-color:var(--ok);background:color-mix(in srgb,var(--ok) 10%,transparent)} | |
| .picked-name{display:inline-block;margin-top:10px;padding:6px 12px;border-radius:999px;background:var(--ok);color:#fff;font-weight:600;font-size:14px;word-break:break-all} | |
| .jobrow{padding:8px 0;border-bottom:1px solid var(--line)}.jobrow:last-of-type{border-bottom:0} | |
| .jobmeta{font-size:13px;color:var(--muted)}.expsoon{color:var(--bad);font-weight:600} | |
| .row{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-top:14px} | |
| @media (max-width:640px){.row{grid-template-columns:1fr}} | |
| label.lb{display:block;font-weight:500;margin-bottom:6px;font-size:13px;color:var(--muted)} | |
| .checks{display:flex;gap:10px;flex-wrap:wrap;margin-top:14px} | |
| .chk{display:flex;align-items:center;gap:7px;background:var(--soft);padding:8px 12px;border-radius:999px;cursor:pointer;font-weight:500} | |
| details{margin-top:14px} | |
| summary{cursor:pointer;color:var(--muted);font-weight:500} | |
| .btn{display:inline-flex;align-items:center;gap:8px;border:0;background:var(--accent);color:var(--accent-ink);padding:12px 22px;border-radius:12px;font:600 15px Inter;cursor:pointer;margin-top:18px} | |
| .btn:disabled{opacity:.5;cursor:default} | |
| .btn.ghost{background:var(--soft);color:var(--ink);padding:9px 14px;margin:6px 6px 0 0;font-size:14px;text-decoration:none} | |
| .bar{height:10px;background:var(--soft);border-radius:99px;overflow:hidden;margin:12px 0 8px} | |
| .bar i{display:block;height:100%;width:0;background:var(--accent);transition:width .4s} | |
| .muted{color:var(--muted)} | |
| .err{color:var(--bad);font-weight:500} | |
| video,audio{width:100%;border-radius:12px;background:#000;margin-top:6px} | |
| table{width:100%;border-collapse:collapse;margin-top:10px;font-size:14px} | |
| th,td{text-align:left;vertical-align:top;padding:9px 8px;border-bottom:1px solid var(--line)} | |
| th{font-size:12px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted)} | |
| td.t{white-space:nowrap;color:var(--muted);font-variant-numeric:tabular-nums;width:56px} | |
| .pill{display:inline-block;background:var(--soft);border-radius:999px;padding:2px 10px;font-size:13px;margin-right:6px} | |
| .jobs a{color:var(--ink)} | |
| .hidden{display:none} | |
| .tablewrap{overflow-x:auto} | |
| .fb{white-space:nowrap;width:118px} | |
| .fb button{border:1px solid var(--line);background:var(--card);border-radius:8px;padding:3px 7px;cursor:pointer;font-size:14px;margin-right:3px} | |
| .fb button.on{background:var(--soft);border-color:var(--accent)} | |
| .fix{display:flex;gap:6px;margin-top:6px}.fix textarea{min-height:44px;font-size:14px}.fix button{border:0;background:var(--accent);color:var(--accent-ink);border-radius:8px;padding:0 12px;font-weight:600;cursor:pointer} | |
| .readbar{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:22px} | |
| .readbar .btn.ghost{margin:0} | |
| .seg{display:inline-flex;background:var(--soft);border-radius:10px;padding:3px;margin-left:auto} | |
| .seg button{border:0;background:none;color:var(--muted);font:600 13px Inter;padding:6px 12px;border-radius:8px;cursor:pointer} | |
| .seg button.on{background:var(--card);color:var(--ink);box-shadow:0 1px 2px rgba(0,0,0,.08)} | |
| .readview{margin-top:12px;padding:18px 20px;background:var(--bg);border:1px solid var(--line);border-radius:12px;font-size:16px;line-height:1.7;max-height:70vh;overflow-y:auto;white-space:pre-wrap;word-wrap:break-word} | |
| .readview p{margin:0 0 1em}.readview p:last-child{margin:0} | |
| .copied{color:var(--ok);font-size:13px;font-weight:600} | |
| .notice{margin:0 0 12px;padding:10px 14px;border-radius:12px;background:var(--soft);font-size:14px} | |
| .support{margin-top:14px;padding:14px 16px;border-radius:12px;border:1px solid var(--line);background:color-mix(in srgb,#f5c542 14%,var(--card));font-size:14px;line-height:1.55} | |
| .support .st{display:block;margin-bottom:4px;font-size:15px} | |
| .drivebox{margin-top:16px;padding:14px 16px;border:1px solid var(--line);border-radius:12px;background:var(--bg)} | |
| .drivebox .row{display:flex;flex-wrap:wrap;gap:6px;align-items:center} | |
| .drivebox .btn.ghost{margin:0} | |
| .drivebox input[type=text]{width:auto;flex:1;min-width:160px;padding:8px 10px;font-size:14px} | |
| .drivebox label{font-size:14px} | |
| #driveMsg{font-size:13px;margin-top:8px} | |
| .human{display:inline-block;font-size:11px;background:var(--soft);color:var(--ok);border-radius:99px;padding:1px 8px;margin-left:6px} | |
| .ok{color:var(--ok);font-size:12px} | |
| .sw{display:flex;align-items:center;justify-content:space-between;gap:12px;background:var(--soft);padding:12px 14px;border-radius:12px;margin-top:10px;cursor:pointer} | |
| .sw b{display:block;font-weight:600}.sw small{color:var(--muted)} | |
| .sw input{appearance:none;width:46px;height:28px;border-radius:99px;background:var(--line);position:relative;flex:none;cursor:pointer;transition:.2s} | |
| .sw input:checked{background:var(--accent)} | |
| .sw input::after{content:"";position:absolute;top:3px;left:3px;width:22px;height:22px;border-radius:50%;background:#fff;transition:.2s} | |
| .sw input:checked::after{left:21px} | |
| .badge{display:inline-block;font-size:11px;font-weight:600;background:var(--accent);color:var(--accent-ink);border-radius:99px;padding:1px 8px;margin-left:6px;vertical-align:middle} | |
| .rec{background:var(--soft);color:var(--ink)}.rec.on{background:var(--bad);color:#fff} | |
| .prompt{font:600 18px Fraunces,Georgia,serif;margin:6px 0 10px} | |
| #install{display:none} | |
| .sw.hidden{display:none} | |
| .agebar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px}.agebar select{width:auto;min-width:150px} | |
| .teen .adultOnly{display:none}.teen #recBtn{display:none} | |
| .teenbadge{display:inline-block;background:var(--soft);color:var(--ok);border-radius:99px;padding:2px 10px;font-size:13px;font-weight:600} | |
| .agree{display:flex;gap:10px;align-items:flex-start;font-size:14px;margin-top:12px;line-height:1.45}.agree input{margin-top:3px;flex:none;width:18px;height:18px} | |
| footer a{color:var(--muted)} | |
| .agree a,#ageDisclaimer a{color:var(--accent)} | |
| @media (max-width:640px){ | |
| .wrap{padding:18px 12px 90px}h1{font-size:30px}.card{padding:16px;border-radius:14px} | |
| .btn{width:100%;justify-content:center;padding:15px}.btn.ghost{width:auto} | |
| input[type=text],input[type=url],select,textarea{font-size:16px;padding:13px} | |
| table thead{display:none}table,tbody,tr,td{display:block;width:100%} | |
| tr{border-bottom:1px solid var(--line);padding:10px 0}td{border:0;padding:3px 0} | |
| td.t{width:auto}.fb{width:auto}.fb button{padding:8px 14px;font-size:17px;margin:6px 6px 0 0} | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="wrap"> | |
| <header><h1>Switch<span>Lingo</span></h1><button id="install" class="btn ghost" style="margin:0 0 0 auto">📲 Add to phone</button><div class="tag">AI video translation. Subtitles and voice-over in 100+ languages, and it learns from your fixes.</div></header> | |
| <section class="card demo"> | |
| <h2>See it switch</h2> | |
| <p class="muted" style="margin-top:-6px">One video, three languages: English original → Spanish → Lao. Made with this site.</p> | |
| <video controls playsinline preload="none" poster="demo-poster.jpg" src="demo.mp4"></video> | |
| </section> | |
| <section class="card"> | |
| <div class="agebar"><label class="lb" for="age" style="margin:0">Your age</label> | |
| <select id="age"><option value="">Choose…</option><option value="teen">13–17</option><option value="adult">18 or older</option><option value="kid">Under 13</option></select> | |
| <span id="ageNote" class="muted"></span></div> | |
| <p id="ageDisclaimer" class="muted" style="font-size:12.5px;margin:-6px 0 12px">By choosing an age you confirm it's true. Giving a false age breaks our <a href="terms.html" target="_blank">Terms</a> and may end your access. Ages 13–17 should use SwitchLingo with a parent or guardian's permission.</p> | |
| <div id="breakNote" class="notice hidden">⏸️ You've been on SwitchLingo a while. Time to stretch, grab some water, or rest your eyes. <a href="#" onclick="event.preventDefault();this.parentNode.classList.add('hidden')">OK</a></div> | |
| <div id="kidMsg" class="err hidden">Sorry, SwitchLingo is for ages 13 and up. Ask a parent or teacher to help you.</div> | |
| <h2>1. Add your video or audio</h2> | |
| <div class="tabs"><button id="tLink" class="on">🔗 Link</button><button id="tFile">📁 Upload</button><button id="tRec">🎤 Record</button></div> | |
| <div id="pLink"><input id="url" type="url" inputmode="url" placeholder="Facebook, Instagram, TikTok, YouTube, X, or any website with a video"> | |
| <p class="muted hidden" id="ytTip" style="font-size:13px;margin:6px 0 0">💡 YouTube often blocks our servers. If the link fails: <b>Android</b>: save it with Seal, then Share → SwitchLingo. <b>Computer</b>: use 🎤 Record → "Record a browser tab". <b>iPhone</b>: save the video to Photos, then Upload.</p></div> | |
| <div id="pFile" class="hidden"> | |
| <div id="drop" class="drop">Tap to choose a video or voice recording<br><small class="muted">mp4, mov, m4a, mp3, wav, amr, 3gp, ogg, opus…</small><br><small id="fname"></small></div> | |
| <input id="file" type="file" accept="video/*,audio/*,.m4a,.mp3,.wav,.amr,.3gp,.3ga,.aac,.ogg,.oga,.opus,.flac,.wma,.webm,.mkv,.mov,.mp4" hidden> | |
| </div> | |
| <div id="pRec" class="hidden"> | |
| <div class="drop" id="recMain">🎤 Tap to start recording<br><small class="muted">Speak or hold your phone near the speaker. Up to 10 minutes.</small></div> | |
| <button type="button" class="btn ghost hidden" id="tabRec" style="width:auto">🖥️ Record a browser tab instead (YouTube, Zoom, any site)</button> | |
| <p class="muted hidden" id="tabHelp" style="font-size:13px;margin:6px 0 0">Pick the tab with the video, turn on <b>"Also share tab audio"</b>, then press play. Click Stop when it's done.</p> | |
| <audio id="recMainPlay" controls class="hidden"></audio> | |
| <p class="muted" style="font-size:13px;margin:8px 0 0">⚠️ Only record people who agreed to be recorded. California and several other states require everyone's consent.</p> | |
| </div> | |
| <div class="row"> | |
| <div><label class="lb" for="src">Spoken language</label><select id="src"><option value="">Auto-detect</option></select></div> | |
| <div><label class="lb" for="tgt">Translate to</label><select id="tgt"></select></div> | |
| </div> | |
| <div class="checks"> | |
| <label class="chk"><input type="checkbox" value="text" checked disabled> Translated text</label> | |
| <label class="chk"><input type="checkbox" class="out" value="subs" checked> Subtitles on video</label> | |
| <label class="chk"><input type="checkbox" class="out" value="dub" checked> Voice-over</label> | |
| </div> | |
| <label class="sw" id="cleanWrap"><span><b>🧼 Clean mode</b><small>Hides swear words in subtitles and skips them in the voice-over</small></span><input type="checkbox" id="clean"></label> | |
| <div class="adultOnly"> | |
| <label class="sw"><span><b>🎙️ Keep the speaker's voice</b><small>Voice-over sounds like the person in the video</small></span><input type="checkbox" id="clone" checked></label> | |
| <label class="agree" id="vcWrap"><input type="checkbox" id="voiceConsent"><span>It's my own voice, or I have the speaker's permission to recreate their voice. I won't use it to impersonate or deceive anyone.</span></label> | |
| <label class="sw hidden" id="lipWrap"><span><b>👄 Lip-sync <span class="badge">PRO</span></b><small>Mouths move with the new language (takes ~2 min longer)</small></span><input type="checkbox" id="lipsync"></label> | |
| </div> | |
| <details> | |
| <summary>Options</summary> | |
| <div class="row"> | |
| <div><label class="lb" for="engine">Translation engine</label><select id="engine"></select></div> | |
| <div><label class="lb" for="quality">Listening accuracy</label> | |
| <select id="quality"><option value="fast">Fast (good for common languages)</option><option value="accurate">Accurate (rare languages, slower)</option></select></div> | |
| <div><label class="lb" for="voice">Voice</label><select id="voice"></select></div> | |
| <div><label class="lb" for="gender">Voice gender</label><select id="gender"><option>Female</option><option>Male</option></select></div> | |
| </div> | |
| </details> | |
| <label class="agree"><input type="checkbox" id="agree"><span>I made this video, own it or have permission to use it, and I agree to the <a href="terms.html" target="_blank">Terms</a> and <a href="privacy.html" target="_blank">Privacy Policy</a>.</span></label> | |
| <button id="go" class="btn">Translate</button> | |
| <p class="muted" style="font-size:13px;margin:10px 0 0"><span id="limits"></span> Only use videos you have the right to share. Every video gets an "AI translated" label. AI voices, even cloned ones, are never the real person speaking. Translations can be wrong, so don't rely on them for medical, legal or immigration decisions.</p> | |
| <div id="formErr" class="err"></div> | |
| </section> | |
| <section id="prog" class="card hidden"> | |
| <h2 id="progTitle">Working on it</h2> | |
| <div class="bar"><i id="barI"></i></div> | |
| <div id="step" class="muted"></div> | |
| </section> | |
| <section id="res" class="card hidden"> | |
| <h2>Result</h2> | |
| <div id="langs"></div> | |
| <div id="player"></div> | |
| <div id="downloads"></div> | |
| <div id="supportCard" class="support hidden"> | |
| <b class="st">💛 This video talks about suicide or self-harm.</b> | |
| If you or someone you know is struggling, you don't have to go through it alone. In the US, call or text <a href="tel:988"><b>988</b></a> (Suicide & Crisis Lifeline, free, 24/7, many languages) or text <b>HOME</b> to <a href="sms:741741">741741</a>. If someone is in danger right now, call <a href="tel:911">911</a>. | |
| </div> | |
| <div id="driveBox" class="drivebox hidden"> | |
| <b style="font-size:14px">Save to your drive</b> | |
| <div class="row" id="driveBtns" style="margin-top:8px"></div> | |
| <div class="row" style="margin-top:10px"><label for="driveFolder">Folder</label><input type="text" id="driveFolder" placeholder="SwitchLingo"></div> | |
| <label style="display:block;margin-top:8px"><input type="checkbox" id="driveAuto"> Save automatically when a translation finishes <span class="muted" id="driveAutoTo"></span></label> | |
| <div id="driveMsg" class="muted"></div> | |
| </div> | |
| <p class="muted" style="font-size:13px;margin:8px 0 0">Labeled "AI translated". Keep the label when you share it. <a id="reportLink" href="report.html">Report this video</a></p> | |
| <div class="readbar"> | |
| <button class="btn ghost" type="button" onclick="copyAll()">📋 Copy all</button> | |
| <button class="btn ghost" type="button" onclick="downloadText()">⬇️ Plain text (.txt)</button> | |
| <span id="copied" class="copied"></span> | |
| <span class="seg" role="tablist"><button type="button" id="vRead" class="on" onclick="setView('read')">Read</button><button type="button" id="vLines" onclick="setView('lines')">Line by line</button></span> | |
| </div> | |
| <div id="readWrap"> | |
| <p class="muted" style="font-size:13px;margin:10px 0 0">Showing <b id="readLang"></b> as one block. <a href="#" id="readSwap" onclick="event.preventDefault();swapReadLang()"></a></p> | |
| <div id="readView" class="readview"></div> | |
| </div> | |
| <div id="linesWrap" class="hidden"> | |
| <h2 style="margin-top:22px">Before & after</h2> | |
| <p class="muted" style="margin-top:-6px;font-size:14px">Speak both languages? Rate each line or fix it with ✏️. Corrections confirmed by other people are reused in future translations and help train the AI.</p> | |
| <div class="tablewrap"><table><thead><tr><th>Time</th><th id="thO">Original</th><th id="thT">Translated</th><th>Rate / fix</th></tr></thead><tbody id="rows"></tbody></table></div> | |
| </div> | |
| </section> | |
| <section class="card"> | |
| <h2>Your recent translations</h2> | |
| <div id="jobs" class="jobs muted">Nothing yet.</div> | |
| </section> | |
| <section class="card" id="teach"> | |
| <h2>🌍 Teach SwitchLingo your language</h2> | |
| <p class="muted" style="margin-top:-6px">Thousands of languages and dialects are missing from big apps, from Lao, Hmong and Navajo to your family's village dialect. Every sentence you add helps SwitchLingo understand your community. Takes 20 seconds.</p> | |
| <form id="teachForm"> | |
| <label class="lb" for="tlang">Language or dialect</label><select id="tlang" name="lang"></select> | |
| <input type="text" id="tother" name="other" class="hidden" maxlength="60" placeholder="Type your language or dialect, e.g. Tai Dam, Garifuna, Sicilian" style="margin-top:8px"> | |
| <div style="margin-top:12px"><label class="lb">Say this in your language <a href="#" id="nextP" style="float:right;color:var(--accent)">another one ↻</a></label> | |
| <div class="prompt" id="tprompt"></div><input type="hidden" name="en" id="ten"></div> | |
| <label class="lb" for="ttext">Type it (your own spelling is fine)</label><textarea id="ttext" name="text" required></textarea> | |
| <div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px"> | |
| <button type="button" class="btn ghost rec" id="recBtn">🎤 Record yourself saying it</button><audio id="recPlay" controls class="hidden" style="max-width:260px;margin:0"></audio> | |
| </div> | |
| <label class="agree"><input type="checkbox" name="agree" value="1" required><span>SwitchLingo may store my sentence (and recording, if I'm 18+ and made one) to improve translations. My recording won't be used to identify me, and I can ask to delete it anytime.</span></label> | |
| <button class="btn" type="submit">Add my sentence</button> <span id="teachMsg" class="muted"></span> | |
| </form> | |
| <p class="muted" style="font-size:13px" id="teachStats"></p> | |
| </section> | |
| <section class="card"> | |
| <h2>Don't see your language?</h2> | |
| <p class="muted" style="margin-top:-6px">Tell us what to add. Requests help decide which languages and dialects get trained next.</p> | |
| <form id="reqForm"> | |
| <div class="row"> | |
| <div><label class="lb">Language or dialect</label><input type="text" name="name" required placeholder="e.g. Isan, Hawaiian, Navajo"></div> | |
| <div><label class="lb">Where it's spoken</label><input type="text" name="region" placeholder="Country / region"></div> | |
| </div> | |
| <div style="margin-top:12px"><label class="lb">Links to audio, video or text in this language (optional)</label><textarea name="notes"></textarea></div> | |
| <button class="btn" type="submit">Send request</button> <span id="reqMsg" class="muted"></span> | |
| </form> | |
| </section> | |
| <section class="card" id="pro"> | |
| <h2>SwitchLingo Pro & API access</h2> | |
| <p class="muted" style="margin-top:-6px">Get early access to paid plans (longer videos, faster results, more languages), or connect SwitchLingo to your app or AI assistant through the API.</p> | |
| <form id="leadForm" novalidate> | |
| <div class="row"> | |
| <div><label class="lb">I'm interested in</label><select name="kind"> | |
| <option value="pro-waitlist">Pro plan for me</option> | |
| <option value="business">Plan for my team or business</option> | |
| <option value="api">API / MCP access</option> | |
| <option value="partner">Partnership or language data</option> | |
| </select></div> | |
| <div><label class="lb">Email</label><input type="text" name="email" inputmode="email" autocomplete="email" required placeholder="you@company.com"></div> | |
| </div> | |
| <div class="row" style="margin-top:12px"> | |
| <div><label class="lb">Name</label><input type="text" name="name" autocomplete="name" maxlength="100"></div> | |
| <div><label class="lb">Company (optional)</label><input type="text" name="org" autocomplete="organization" maxlength="120"></div> | |
| </div> | |
| <div style="margin-top:12px"><label class="lb">What would you use it for? (optional)</label><textarea name="message" maxlength="2000" placeholder="Languages you need, how many videos a month, where the videos come from"></textarea></div> | |
| <input type="text" name="website" tabindex="-1" autocomplete="off" aria-hidden="true" style="position:absolute;left:-9999px"> | |
| <button class="btn" type="submit">Join the list</button> <span id="leadMsg" class="muted" role="status"></span> | |
| <p class="muted" style="font-size:13px;margin-bottom:0">For adults 18+ and businesses. We use your email only to contact you about SwitchLingo.</p> | |
| </form> | |
| </section> | |
| <footer style="text-align:center;font-size:13px;margin-top:10px" class="muted"> | |
| <a href="terms.html">Terms</a> · <a href="privacy.html">Privacy</a> · <a href="report.html">Report a video / Contact</a><br> | |
| SwitchLingo uses AI. Videos it makes carry a visible label and hidden "AI-generated" metadata.<br>A <a href="https://www.novard.ai">Nova R&D Labs</a> project | |
| </footer> | |
| </div> | |
| <script src="drive.js"></script> | |
| <script> | |
| const $ = s => document.querySelector(s); | |
| let mode = "link", file = null, LANG = {}; | |
| const esc = s => (s ?? "").replace(/[&<>"]/g, c => ({"&":"&","<":"<",">":">",'"':"""}[c])); | |
| const fmt = s => { s = Math.floor(s); return `${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`; }; | |
| function setMode(m){ mode=m; [["link","Link"],["file","File"],["rec","Rec"]].forEach(([k,n])=>{ | |
| $("#t"+n).classList.toggle("on",m===k); $("#p"+n).classList.toggle("hidden",m!==k); }); } | |
| $("#url").addEventListener("input",()=>$("#ytTip").classList.toggle("hidden",!/youtu\.?be/i.test($("#url").value))); | |
| $("#tLink").onclick=()=>setMode("link"); $("#tFile").onclick=()=>setMode("file"); $("#tRec").onclick=()=>setMode("rec"); | |
| let mainRec=null, mainBlob=null, recTimer=null; | |
| async function loadSharedFile(){ | |
| try{ const c=await caches.open("sl-shared"); const r=await c.match("/shared-file"); if(!r) return; | |
| const blob=await r.blob(); const name=decodeURIComponent(r.headers.get("x-name")||"shared-video.mp4"); | |
| file=new File([blob],name,{type:blob.type}); await c.delete("/shared-file"); | |
| setMode("file"); $("#fname").textContent="📎 "+name+" (shared from another app)"; | |
| history.replaceState(null,"","/"); $("#go").scrollIntoView({behavior:"smooth",block:"center"}); | |
| }catch(e){} | |
| } | |
| // Desktop: capture a browser tab's audio (works for YouTube and any site, because it runs on the user's own computer) | |
| if(navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia && !/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)){ | |
| $("#tabRec").classList.remove("hidden"); $("#tabHelp").classList.remove("hidden"); | |
| } | |
| let tabRec=null; | |
| $("#tabRec").onclick=async()=>{ | |
| if(tabRec&&tabRec.state==="recording"){ tabRec.stop(); return; } | |
| try{ | |
| const st=await navigator.mediaDevices.getDisplayMedia({video:true,audio:{suppressLocalAudioPlayback:false},preferCurrentTab:false,selfBrowserSurface:"exclude"}); | |
| const at=st.getAudioTracks(); | |
| if(!at.length){ st.getTracks().forEach(t=>t.stop()); $("#formErr").textContent="No sound was shared. Try again and turn on \"Also share tab audio\"."; return; } | |
| const ch=[], t0=Date.now(); tabRec=new MediaRecorder(new MediaStream(at)); tabRec.ondataavailable=e=>ch.push(e.data); | |
| const timer=setInterval(()=>{ const s=Math.floor((Date.now()-t0)/1000); $("#tabRec").textContent=`⏹ Recording tab ${fmt(s)}… click to stop`; if(s>=600) tabRec.stop(); },500); | |
| st.getVideoTracks().forEach(v=>v.onended=()=>tabRec.state==="recording"&&tabRec.stop()); | |
| tabRec.onstop=()=>{ clearInterval(timer); st.getTracks().forEach(t=>t.stop()); mainBlob=new Blob(ch,{type:tabRec.mimeType}); | |
| $("#recMainPlay").src=URL.createObjectURL(mainBlob); $("#recMainPlay").classList.remove("hidden"); | |
| $("#tabRec").textContent="✅ Tab recorded. Click to record again"; }; | |
| tabRec.start(); | |
| }catch(e){ $("#formErr").textContent="Tab recording was cancelled or isn't supported in this browser."; } | |
| }; | |
| $("#recMain").onclick=async()=>{ | |
| if(mainRec&&mainRec.state==="recording"){ mainRec.stop(); return; } | |
| try{ | |
| const st=await navigator.mediaDevices.getUserMedia({audio:true}); const ch=[]; const t0=Date.now(); | |
| mainRec=new MediaRecorder(st); mainRec.ondataavailable=e=>ch.push(e.data); | |
| mainRec.onstop=()=>{ clearInterval(recTimer); st.getTracks().forEach(t=>t.stop()); mainBlob=new Blob(ch,{type:mainRec.mimeType}); | |
| $("#recMainPlay").src=URL.createObjectURL(mainBlob); $("#recMainPlay").classList.remove("hidden"); | |
| $("#recMain").innerHTML="✅ Recorded. Tap to record again"; }; | |
| mainRec.start(); recTimer=setInterval(()=>{ const s=Math.floor((Date.now()-t0)/1000); | |
| $("#recMain").innerHTML=`⏹ Recording ${fmt(s)}… tap to stop`; if(s>=600) mainRec.stop(); },500); | |
| }catch(e){ $("#formErr").textContent="Microphone not allowed. Check your browser settings."; } | |
| }; | |
| const drop=$("#drop"); | |
| drop.onclick=()=>$("#file").click(); | |
| function showPicked(){ | |
| drop.classList.toggle("picked",!!file); | |
| $("#fname").innerHTML=file?`<span class="picked-name">✅ Ready: ${esc(file.name)} · ${(file.size/1048576).toFixed(1)} MB</span><br><small class="muted">Already added. Tap only if you want a different file.</small>`:""; | |
| } | |
| $("#file").onchange=e=>{file=e.target.files[0]; showPicked();}; | |
| ["dragover","dragenter"].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.add("over");})); | |
| ["dragleave","drop"].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.remove("over");})); | |
| drop.addEventListener("drop",e=>{file=e.dataTransfer.files[0]; showPicked();}); | |
| async function init(){ | |
| const r = await (await fetch("/api/languages")).json(); | |
| r.languages.forEach(l=>LANG[l.code]=l); | |
| const opt=l=>`<option value="${l.code}">${esc(l.name)}${l.tts?"":" (no voice yet)"}</option>`; | |
| const pop=r.popular.map(c=>LANG[c]).filter(Boolean); | |
| const rest=r.languages.filter(l=>!r.popular.includes(l.code)); | |
| $("#tgt").insertAdjacentHTML("beforeend",`<optgroup label="Most used in the US">${pop.map(opt).join("")}</optgroup><optgroup label="All languages">${rest.map(opt).join("")}</optgroup>`); | |
| $("#src").insertAdjacentHTML("beforeend",`<optgroup label="Most used in the US">${pop.filter(l=>l.speech).map(opt).join("")}</optgroup><optgroup label="All languages">${rest.filter(l=>l.speech).map(opt).join("")}</optgroup>`); | |
| if(r.limits.keep_hours) KEEP_H=r.limits.keep_hours; | |
| Drive.configure(r.drive); if(RES) renderDrive(); | |
| $("#limits").textContent=`Up to ${r.limits.max_minutes} minutes and ${r.limits.max_mb} MB per video.`; | |
| $("#tgt").value="en"; | |
| const names={madlad:"SwitchLingo AI (400+ languages, incl. Hmong)",nllb:"Meta NLLB (backup)",google:"Google (online)",claude:"Claude (best quality)"}; | |
| r.translators.forEach(t=>$("#engine").insertAdjacentHTML("beforeend",`<option value="${t}">${names[t]||t}</option>`)); | |
| const vn={edge:"Natural voice (free)",elevenlabs:"ElevenLabs (most realistic)"}; | |
| r.voices.forEach(v=>$("#voice").insertAdjacentHTML("beforeend",`<option value="${v}">${vn[v]||v}</option>`)); | |
| if(r.voices.includes("elevenlabs")) $("#voice").value="elevenlabs"; | |
| if(r.translators.includes("claude")) $("#engine").value="claude"; | |
| if(r.lipsync) $("#lipWrap").classList.remove("hidden"); | |
| const vc=()=>$("#vcWrap").style.display=$("#clone").checked?"flex":"none"; $("#clone").onchange=vc; vc(); | |
| try{ const a=localStorage.getItem("oxt_age"); $("#age").value=a||"teen"; }catch(e){ $("#age").value="teen"; } // safer default: Teen mode until someone says they're 18+ | |
| if(teenLocked() && $("#age").value==="adult") $("#age").value="teen"; | |
| if(ageLocked()) $("#age").value="kid"; | |
| applyAge(); | |
| const qs=new URLSearchParams(location.search), shared=qs.get("url")||qs.get("text")||""; | |
| if(qs.get("shared")==="file") loadSharedFile(); | |
| const m=shared.match(/https?:\/\/\S+/); if(m){ setMode("link"); $("#url").value=m[0]; $("#go").scrollIntoView({behavior:"smooth",block:"center"}); } | |
| initTeach(); | |
| loadJobs(); | |
| const id=new URLSearchParams(location.search).get("job"); if(id) watch(id); | |
| } | |
| $("#go").onclick=async()=>{ | |
| $("#formErr").textContent=""; | |
| const fd=new FormData(); | |
| if(mode==="link"){ if(!$("#url").value.trim()) return $("#formErr").textContent="Paste a link first."; fd.append("url",$("#url").value.trim()); } | |
| else if(mode==="file"){ if(!file) return $("#formErr").textContent="Choose a file first."; fd.append("file",file); } | |
| else { if(!mainBlob) return $("#formErr").textContent="Record something first."; fd.append("file",mainBlob,"recording."+((mainBlob.type.split("/")[1]||"webm").split(";")[0])); } | |
| const outs=["text",...[...document.querySelectorAll(".out:checked")].map(c=>c.value)]; | |
| Object.entries({target:$("#tgt").value,source:$("#src").value,engine:$("#engine").value,outputs:outs.join(","), | |
| quality:$("#quality").value,gender:$("#gender").value,voice_engine:$("#voice").value, | |
| clone:$("#clone").checked?"1":"0",lipsync:$("#lipsync").checked?"1":"0"}).forEach(([k,v])=>fd.append(k,v)); | |
| if(!$("#agree").checked) return $("#formErr").textContent="Please check the box to confirm you have the right to use this video."; | |
| const age=$("#age").value; | |
| if(age==="kid") return $("#formErr").textContent="Sorry, SwitchLingo is for ages 13 and up."; | |
| if(!age) return $("#formErr").textContent="Please choose your age group first."; | |
| fd.append("age",age); fd.append("clean",(age==="teen"||$("#clean").checked)?"1":"0"); | |
| if(age==="adult" && $("#clone").checked && outs.includes("dub") && !$("#voiceConsent").checked) return $("#formErr").textContent="To keep the speaker's voice, confirm you have their permission (or turn that switch off)."; | |
| fd.append("agree","1"); fd.append("voice_consent",$("#voiceConsent").checked?"1":"0"); | |
| $("#go").disabled=true; $("#go").textContent="Uploading…"; | |
| try{ | |
| const r=await fetch("/api/jobs",{method:"POST",body:fd}); const j=await r.json(); | |
| if(!r.ok) throw new Error(j.detail||"Something went wrong"); | |
| rememberJob(j.id); history.replaceState(null,"","?job="+j.id); watch(j.id); | |
| }catch(e){ $("#formErr").textContent=e.message; } | |
| $("#go").disabled=false; $("#go").textContent="Translate"; | |
| }; | |
| async function watch(id){ | |
| $("#prog").classList.remove("hidden"); $("#res").classList.add("hidden"); | |
| for(;;){ | |
| $("#progTitle").textContent="Working on it"; | |
| let r; try{ r=await fetch("/api/jobs/"+id); }catch(e){ await new Promise(x=>setTimeout(x,3000)); continue; } | |
| if(r.status===404){ $("#progTitle").textContent="Not available"; | |
| $("#step").innerHTML='<span class="err">This translation expired (results are kept 24 hours) or was removed. Please translate it again.</span>'; | |
| $("#barI").style.width="0"; history.replaceState(null,"","/"); return; } | |
| const j=await r.json(); | |
| $("#barI").style.width=Math.round((j.progress||0)*100)+"%"; | |
| $("#step").innerHTML=j.status==="error"?`<span class="err">${esc(j.error)}</span>`:esc(j.step||j.status||"Starting…"); | |
| if(j.status==="done"){ $("#prog").classList.add("hidden"); show(j); loadJobs(); return; } | |
| if(j.status==="error"){ $("#progTitle").textContent="Couldn't translate this one"; $("#barI").style.width="0"; loadJobs(); return; } | |
| await new Promise(r=>setTimeout(r,1500)); | |
| } | |
| } | |
| function show(j){ | |
| const r=j.result, f=r.files, url=n=>`/api/files/${j.id}/${encodeURIComponent(n)}`; | |
| $("#langs").innerHTML=`<span class="pill">${esc(r.source_name)} → ${esc(r.target_name)}</span><span class="pill">${fmt(r.duration)}</span>` | |
| + (r.voice_cloned?'<span class="pill">🎙️ speaker\'s voice</span>':'') + (f.lipsync?'<span class="pill">👄 lip-synced</span>':'') | |
| + (r.auto_detected && r.detect_confidence < 0.85 ? `<p class="err">Heard ${esc(r.source_name)}, but only ${Math.round(r.detect_confidence*100)}% sure. If that's wrong, set "Spoken language" above and translate again. Mixed-language speech (e.g. Somali with English words) often fools auto-detect.</p>` : ""); | |
| const main=f.lipsync||f.voiceover||f.subtitled; | |
| $("#player").innerHTML = main ? (main.endsWith(".m4a")?`<audio controls src="${url(main)}"></audio>`:`<video controls playsinline src="${url(main)}"></video>`) : ""; | |
| const labels={lipsync:"Lip-synced video",voiceover:"Voice-over",subtitled:"Subtitled video",translated_srt:"Translated subtitles (.srt)",original_srt:"Original subtitles (.srt)",transcript:"Side-by-side transcript (.txt)",original:"Original media"}; | |
| $("#reportLink").href="report.html?job="+j.id; | |
| $("#downloads").innerHTML=Object.entries(labels).filter(([k])=>f[k]).map(([k,l])=>`<a class="btn ghost" href="${url(f[k])}?download=true">${l}</a>`).join(""); | |
| $("#thO").textContent="Before — "+r.source_name; $("#thT").textContent="After — "+r.target_name; | |
| CUR=j.id; | |
| $("#rows").innerHTML=r.segments.map((s,i)=>`<tr><td class="t">${fmt(s.s)}</td><td>${esc(s.original)}</td><td><span id="tx${i}">${esc(s.translated)}</span>${s.human?'<span class="human">fixed by people</span>':''}<div id="fx${i}"></div></td> | |
| <td class="fb"><button title="Good" onclick="rate(${i},1,this)">👍</button><button title="Wrong" onclick="rate(${i},-1,this)">👎</button><button title="Fix it" onclick="fixBox(${i})">✏️</button><div id="ok${i}" class="ok"></div></td></tr>`).join(""); | |
| $("#langs").innerHTML+=`<span class="pill">🕒 ${when(j.created)}</span><span class="pill">${expiry(j)}</span>`; | |
| $("#supportCard").classList.toggle("hidden",!r.support); | |
| JOB=j; RES=r; READ_ORIG=false; renderRead(); setView(VIEW); renderDrive(); autoSave(j); | |
| $("#res").classList.remove("hidden"); | |
| } | |
| // ---- Read view: the whole transcript as one easy-to-read block (includes people's fixes) | |
| let KEEP_H=24; | |
| function when(t){ if(!t) return ""; return new Date(t*1000).toLocaleString([], {weekday:"short",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}); } | |
| function expiry(j){ const end=((j.finished||j.created||0)+KEEP_H*3600)*1000, left=end-Date.now(); | |
| if(left<=0) return '<span class="expsoon">Expired</span>'; | |
| const h=Math.floor(left/3600000), m=Math.floor(left%3600000/60000); | |
| const txt=`Deleted in ${h?h+"h ":""}${m}m (${new Date(end).toLocaleString([], {weekday:"short",hour:"numeric",minute:"2-digit"})})`; | |
| return h<2?`<span class="expsoon">${txt}</span>`:txt; } | |
| let RES=null, READ_ORIG=false, VIEW=(()=>{ try{ return localStorage.getItem("oxt_view")||"read"; }catch(e){ return "read"; } })(); | |
| function lineText(i,orig){ const s=RES.segments[i]; return (orig ? s.original : ($("#tx"+i)?.textContent ?? s.translated) || "").trim(); } | |
| function readText(orig){ | |
| // Same rules as the server: new paragraph after a 2-second pause, or ~500 characters at a sentence end | |
| const paras=[]; let cur=[], len=0, last=null; | |
| RES.segments.forEach((s,i)=>{ const t=lineText(i,orig); if(!t) return; | |
| if(cur.length && ((last!==null && s.s-last>=2) || (len>=500 && /[.!?。!?]$/.test(cur[cur.length-1])))){ paras.push(cur.join(" ")); cur=[]; len=0; } | |
| cur.push(t); len+=t.length+1; last=s.e; }); | |
| if(cur.length) paras.push(cur.join(" ")); | |
| return paras.join("\n\n"); | |
| } | |
| function renderRead(){ if(!RES) return; | |
| const name=READ_ORIG?RES.source_name:RES.target_name, other=READ_ORIG?RES.target_name:RES.source_name; | |
| $("#readLang").textContent=name+(READ_ORIG?" (original)":""); | |
| $("#readSwap").textContent="Show "+other+(READ_ORIG?"":" (original)")+" instead"; | |
| $("#readSwap").style.display=RES.source_lang===RES.target_lang?"none":""; | |
| $("#readView").innerHTML=readText(READ_ORIG).split("\n\n").map(p=>`<p>${esc(p)}</p>`).join("") || '<span class="muted">No speech found.</span>'; | |
| } | |
| // ---- Save to Google Drive / OneDrive (files go straight from this browser to the visitor's drive) | |
| let JOB=null; | |
| function baseName(){ const j=JOB, d=new Date((j.created||Date.now()/1000)*1000); | |
| const stamp=d.getFullYear()+"-"+String(d.getMonth()+1).padStart(2,"0")+"-"+String(d.getDate()).padStart(2,"0")+" "+String(d.getHours()).padStart(2,"0")+String(d.getMinutes()).padStart(2,"0"); | |
| const src=String(j.input||"video").split(/[\/?#]/).filter(Boolean).pop().replace(/\.[a-z0-9]{2,4}$/i,"").replace(/[\\:*?"<>|]/g,"").slice(0,60)||"video"; | |
| return `${stamp} ${src}`; } | |
| async function driveFiles(){ const f=RES.files, b=baseName(), out=[]; | |
| out.push({name:`${b} (${RES.target_lang}).txt`, blob:new Blob([readText(false)+"\n"],{type:"text/plain"})}); | |
| for(const [k,label] of [["transcript","side-by-side"],["translated_srt","subtitles "+RES.target_lang]]){ | |
| if(!f[k]) continue; const r=await fetch(`/api/files/${JOB.id}/${encodeURIComponent(f[k])}`); | |
| if(r.ok) out.push({name:`${b} (${label}).${f[k].split(".").pop()}`, blob:new Blob([await r.blob()],{type:"text/plain"})}); } | |
| return out; } | |
| async function saveTo(p, interactive=true){ | |
| const msg=$("#driveMsg"); msg.className="muted"; msg.textContent=`Saving to ${Drive.name(p)}…`; | |
| try{ const link=await Drive.save(p, await driveFiles(), interactive); | |
| try{ localStorage.setItem("sl_saved_"+JOB.id,p); }catch(e){} | |
| if($("#driveAuto").checked) Drive.setAuto(p); renderDriveAuto(); | |
| msg.className="copied"; msg.innerHTML=`✅ Saved to ${Drive.name(p)} › ${esc(Drive.folder())}`+(link?` · <a href="${esc(link)}" target="_blank" rel="noopener">Open folder</a>`:""); | |
| }catch(e){ msg.className="err"; msg.textContent=e.message==="signin"?`Tap “Save to ${Drive.name(p)}” to sign in and finish saving.`:`Couldn't save: ${e.message}`; } } | |
| function renderDriveAuto(){ const a=Drive.auto(); $("#driveAuto").checked=!!a; $("#driveAutoTo").textContent=a?`(to ${Drive.name(a)})`:""; } | |
| function renderDrive(){ const ps=Drive.available(); $("#driveBox").classList.toggle("hidden",!ps.length); if(!ps.length) return; | |
| $("#driveBtns").innerHTML=ps.map(p=>`<button type="button" class="btn ghost" onclick="saveTo('${p}')">${p==="google"?"🟢 Save to Google Drive":"🔵 Save to OneDrive"}</button>`).join(""); | |
| $("#driveFolder").value=Drive.folder(); renderDriveAuto(); } | |
| function autoSave(j){ const p=Drive.auto(); if(!p||!Drive.available().includes(p)) return; | |
| let done=null; try{ done=localStorage.getItem("sl_saved_"+j.id); }catch(e){} if(done) return; | |
| if(Date.now()/1000-(j.finished||0) > 600) return; // only fresh results, not old ones reopened later | |
| saveTo(p, false); } | |
| $("#driveFolder").onchange=e=>Drive.setFolder(e.target.value.trim()); | |
| $("#driveAuto").onchange=e=>{ const ps=Drive.available(); Drive.setAuto(e.target.checked?(Drive.auto()||ps[0]):""); renderDriveAuto(); | |
| if(e.target.checked) $("#driveMsg").textContent=`New translations will save to ${Drive.name(Drive.auto())} › ${Drive.folder()} while this page is open. Use the button once to sign in.`; }; | |
| function swapReadLang(){ READ_ORIG=!READ_ORIG; renderRead(); } | |
| function setView(v){ VIEW=v; try{ localStorage.setItem("oxt_view",v); }catch(e){} | |
| $("#readWrap").classList.toggle("hidden",v!=="read"); $("#linesWrap").classList.toggle("hidden",v!=="lines"); | |
| $("#vRead").classList.toggle("on",v==="read"); $("#vLines").classList.toggle("on",v==="lines"); } | |
| async function copyAll(){ const t=readText(READ_ORIG); | |
| try{ await navigator.clipboard.writeText(t); } | |
| catch(e){ const a=document.createElement("textarea"); a.value=t; document.body.appendChild(a); a.select(); document.execCommand("copy"); a.remove(); } | |
| $("#copied").textContent="Copied!"; setTimeout(()=>$("#copied").textContent="",2000); } | |
| function downloadText(){ const lang=READ_ORIG?RES.source_lang:RES.target_lang; | |
| const a=document.createElement("a"); a.href=URL.createObjectURL(new Blob([readText(READ_ORIG)+"\n"],{type:"text/plain;charset=utf-8"})); | |
| a.download=`switchlingo-${CUR||"text"}-${lang}.txt`; document.body.appendChild(a); a.click(); a.remove(); setTimeout(()=>URL.revokeObjectURL(a.href),1000); } | |
| let CUR=null; | |
| const ADMIN=(()=>{ try{ const t=new URLSearchParams(location.search).get("admin"); if(t) localStorage.setItem("oxt_admin",t); return localStorage.getItem("oxt_admin")||""; }catch(e){ return ""; } })(); | |
| async function sendFb(i,rating,correction){ | |
| const fd=new FormData(); Object.entries({job_id:CUR,seg:i,rating,correction,token:ADMIN}).forEach(([k,v])=>fd.append(k,v)); | |
| const r=await fetch("/api/feedback",{method:"POST",body:fd}); $("#ok"+i).textContent=r.ok?"Thanks!":"Not saved"; return r.ok; | |
| } | |
| function rate(i,v,b){ b.parentNode.querySelectorAll("button").forEach(x=>x.classList.remove("on")); b.classList.add("on"); sendFb(i,v,""); if(v<0) fixBox(i); } | |
| function fixBox(i){ const el=$("#fx"+i); if(el.innerHTML) return el.innerHTML=""; | |
| el.innerHTML=`<div class="fix"><textarea id="fv${i}">${esc($("#tx"+i).textContent)}</textarea><button onclick="saveFix(${i})">Save</button></div>`; $("#fv"+i).focus(); } | |
| async function saveFix(i){ const v=$("#fv"+i).value.trim(); if(!v) return; | |
| if(await sendFb(i,-1,v)){ $("#tx"+i).textContent=v; $("#fx"+i).innerHTML=""; renderRead(); } } | |
| function myJobs(){ try{ return JSON.parse(localStorage.getItem("oxt_jobs")||"[]"); }catch(e){ return []; } } | |
| function rememberJob(id){ try{ localStorage.setItem("oxt_jobs", JSON.stringify([id,...myJobs().filter(x=>x!==id)].slice(0,15))); }catch(e){} } | |
| async function loadJobs(){ | |
| const ids=myJobs(); if(!ids.length) return; | |
| const jobs=(await Promise.all(ids.map(id=>fetch("/api/jobs/"+id).then(r=>r.ok?r.json():null).catch(()=>null)))).filter(Boolean); | |
| if(!jobs.length) return; | |
| jobs.sort((a,b)=>(b.created||0)-(a.created||0)); | |
| $("#jobs").innerHTML=jobs.map(j=>`<div class="jobrow"><a href="?job=${j.id}" onclick="event.preventDefault();history.replaceState(null,'','?job=${j.id}');watch('${j.id}')">${esc(j.input).slice(0,70)}</a> → ${esc(LANG[j.target]?.name||j.target)} · <span>${j.status}</span> | |
| <div class="jobmeta">🕒 ${when(j.created)}${j.status==="done"||j.status==="error"?" · "+expiry(j):""}</div></div>`).join("") | |
| + `<p class="muted" style="font-size:13px">Results are deleted ${KEEP_H} hours after they finish. Download or copy anything you want to keep.</p>`; | |
| } | |
| $("#reqForm").onsubmit=async e=>{ e.preventDefault(); | |
| const r=await fetch("/api/language-requests",{method:"POST",body:new FormData(e.target)}); | |
| $("#reqMsg").textContent=r.ok?"Thanks, request saved.":"Couldn't save, try again."; if(r.ok) e.target.reset(); }; | |
| function ageLocked(){ try{ return Number(localStorage.getItem("oxt_kidlock")||0) > Date.now(); }catch(e){ return false; } } | |
| function applyAge(){ | |
| if(ageLocked() && $("#age").value!=="kid"){ $("#age").value="kid"; } | |
| if($("#age").value==="kid"){ try{ if(!ageLocked()) localStorage.setItem("oxt_kidlock", String(Date.now()+30*24*3600*1000)); }catch(e){} } | |
| const a=$("#age").value, teen=a==="teen"; | |
| document.body.classList.toggle("teen",teen); | |
| $("#kidMsg").classList.toggle("hidden",a!=="kid"); | |
| $("#go").disabled=(a==="kid"); | |
| $("#clean").checked=teen?true:$("#clean").checked; $("#clean").disabled=teen; | |
| const until=adultAfter(); | |
| $("#ageNote").innerHTML=teen?('<span class="teenbadge">Teen mode</span> Clean words · standard AI voice' | |
| + (until>Date.now()?` · adult mode unlocks ${new Date(until).toLocaleString([], {weekday:"short",hour:"numeric",minute:"2-digit"})}` | |
| : (teenLocked()?"":" · adults: choose 18 or older"))):(a==="adult"?"":""); | |
| startBreakTimer(teen); | |
| if(teen) $("#voice").value="edge"; | |
| try{ if(a==="teen"||a==="adult") localStorage.setItem("oxt_age",a); }catch(e){} | |
| } | |
| // Teen lock (like Meta's rule that going from under-18 to adult needs extra proof): once this device picks 13-17, | |
| // switching to adult needs a confirmation and only takes effect after 24 hours. | |
| function teenLocked(){ try{ return localStorage.getItem("oxt_teenlock")==="1"; }catch(e){ return false; } } | |
| function adultAfter(){ try{ return Number(localStorage.getItem("oxt_adult_after")||0); }catch(e){ return 0; } } | |
| function userAgeChange(){ | |
| const a=$("#age").value; | |
| try{ | |
| if(a==="teen"){ localStorage.setItem("oxt_teenlock","1"); localStorage.removeItem("oxt_adult_after"); } | |
| if(a==="adult" && teenLocked()){ | |
| const until=adultAfter(); | |
| if(until && until<=Date.now()){ localStorage.removeItem("oxt_teenlock"); localStorage.removeItem("oxt_adult_after"); } | |
| else { | |
| if(!until){ | |
| const ok=confirm("This device was set to ages 13–17.\n\nOnly switch if you are 18 or older. Giving a false age breaks our Terms.\n\nFor safety, adult mode turns on 24 hours from now."); | |
| if(ok) localStorage.setItem("oxt_adult_after", String(Date.now()+24*3600*1000)); | |
| } | |
| $("#age").value="teen"; | |
| } | |
| } | |
| }catch(e){} | |
| applyAge(); | |
| } | |
| $("#age").onchange=userAgeChange; | |
| // Break reminders for Teen mode (like ChatGPT's in-app reminders during long sessions) | |
| let BREAK_T=null; | |
| function startBreakTimer(on){ | |
| clearTimeout(BREAK_T); if(!on) return; | |
| let start; try{ start=Number(sessionStorage.getItem("oxt_session_start")||0); if(!start){ start=Date.now(); sessionStorage.setItem("oxt_session_start",String(start)); } }catch(e){ start=Date.now(); } | |
| const every=45*60*1000, wait=every-((Date.now()-start)%every); | |
| BREAK_T=setTimeout(()=>{ $("#breakNote").classList.remove("hidden"); startBreakTimer($("#age").value==="teen"); }, wait); | |
| } | |
| let recBlob=null, recorder=null, PROMPTS=[]; | |
| async function initTeach(){ | |
| const r=await (await fetch("/api/teach/languages")).json(); PROMPTS=r.prompts; | |
| const o=([k,v])=>`<option value="${k}">${esc(v)}</option>`; | |
| const pop=r.popular.filter(c=>r.languages[c]).map(c=>[c,r.languages[c]]); | |
| const dia=Object.entries(r.dialects).sort((a,b)=>a[1].localeCompare(b[1])); | |
| $("#tlang").innerHTML=`<optgroup label="Most spoken in the US">${pop.map(o).join("")}</optgroup>` | |
| +`<optgroup label="Dialects & community languages">${dia.map(o).join("")}</optgroup>` | |
| +`<optgroup label="All languages">${Object.entries(r.languages).map(o).join("")}</optgroup>` | |
| +`<optgroup label="Not listed?"><option value="other">➕ Other language or dialect…</option></optgroup>`; | |
| try{ const last=localStorage.getItem("oxt_teachlang"); if(last) $("#tlang").value=last; }catch(e){} | |
| $("#tlang").onchange=()=>{ const ot=$("#tlang").value==="other"; $("#tother").classList.toggle("hidden",!ot); if(ot) $("#tother").focus(); | |
| try{ localStorage.setItem("oxt_teachlang",$("#tlang").value); }catch(e){} }; | |
| $("#tlang").onchange(); | |
| nextPrompt(); teachStats(); | |
| } | |
| function nextPrompt(){ const p=PROMPTS[Math.floor(Math.random()*PROMPTS.length)]; $("#tprompt").textContent="“"+p+"”"; $("#ten").value=p; } | |
| $("#nextP").onclick=e=>{e.preventDefault(); nextPrompt();}; | |
| async function teachStats(){ try{ const s=await (await fetch("/api/feedback/stats")).json(); | |
| const by=Object.entries(s.pairs_by_language||{}).map(([k,v])=>`${esc(k)} ${v}`).join(" · "); | |
| $("#teachStats").textContent=`${s.sentence_pairs||0} sentences taught so far${by?" ("+by+")":""} · ${s.corrections||0} fixes from viewers.`; }catch(e){} } | |
| $("#recBtn").onclick=async()=>{ | |
| if(recorder&&recorder.state==="recording"){ recorder.stop(); return; } | |
| try{ | |
| const st=await navigator.mediaDevices.getUserMedia({audio:true}); const ch=[]; | |
| recorder=new MediaRecorder(st); recorder.ondataavailable=e=>ch.push(e.data); | |
| recorder.onstop=()=>{ st.getTracks().forEach(t=>t.stop()); recBlob=new Blob(ch,{type:recorder.mimeType}); | |
| $("#recPlay").src=URL.createObjectURL(recBlob); $("#recPlay").classList.remove("hidden"); | |
| $("#recBtn").classList.remove("on"); $("#recBtn").textContent="🎤 Record again"; }; | |
| recorder.start(); $("#recBtn").classList.add("on"); $("#recBtn").textContent="⏹ Stop recording"; | |
| setTimeout(()=>recorder&&recorder.state==="recording"&&recorder.stop(),30000); | |
| }catch(e){ $("#teachMsg").textContent="Microphone not allowed. You can still type it."; } | |
| }; | |
| $("#leadForm").onsubmit=async e=>{ e.preventDefault(); | |
| const f=e.target, d=Object.fromEntries(new FormData(f)), m=$("#leadMsg"); | |
| if(!/^[^\s@]+@[^\s@]+\.[a-z]{2,}$/i.test(d.email||"")){ m.textContent="Please enter a valid email."; return; } | |
| const b=f.querySelector("button"); b.disabled=true; m.textContent="Sending…"; | |
| try{ const r=await fetch("https://novard.ai/api/lead",{method:"POST",headers:{"content-type":"application/json"}, | |
| body:JSON.stringify({...d,source:"switchlingo",meta:{page:location.pathname}})}); | |
| const j=await r.json(); if(!j.ok) throw new Error(j.error||"Could not send"); | |
| f.reset(); m.textContent="You're on the list. We'll email you soon."; } | |
| catch(x){ m.textContent=x.message||"Could not send. Email info@novard.ai."; } | |
| b.disabled=false; }; | |
| $("#teachForm").onsubmit=async e=>{ e.preventDefault(); | |
| const age=$("#age").value; if(age!=="teen"&&age!=="adult"){ $("#teachMsg").textContent="Choose your age group at the top first (13+)."; return; } | |
| const fd=new FormData(e.target); fd.append("token",ADMIN); fd.append("age",age); | |
| if(recBlob) fd.append("audio",recBlob,"rec."+((recBlob.type.split("/")[1]||"webm").split(";")[0])); | |
| const r=await fetch("/api/teach",{method:"POST",body:fd}); | |
| $("#teachMsg").textContent=r.ok?"Thank you! 🙏 Added.":"Couldn't save, try again."; | |
| if(r.ok){ $("#ttext").value=""; recBlob=null; $("#recPlay").classList.add("hidden"); $("#recBtn").textContent="🎤 Record yourself saying it"; nextPrompt(); teachStats(); } }; | |
| // phone: installable app + share-to-SwitchLingo | |
| if("serviceWorker" in navigator) navigator.serviceWorker.register("sw.js").catch(()=>{}); | |
| let deferred=null; | |
| window.addEventListener("beforeinstallprompt",e=>{ e.preventDefault(); deferred=e; $("#install").style.display="inline-flex"; }); | |
| $("#install").onclick=async()=>{ if(!deferred) return; deferred.prompt(); await deferred.userChoice; deferred=null; $("#install").style.display="none"; }; | |
| init(); | |
| </script> | |
| </body> | |
| </html> | |