Spaces:
Build error
Build error
Download index.html from AInive/Nive-AI-Lite: direct link, hf CLI and curl.
- Browser
- Download file 20.5 kB
-
https://huggingface.co/spaces/AInive/Nive-AI-Lite/resolve/main/index.html
- Command line
-
hf download hf://spaces/AInive/Nive-AI-Lite/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AInive/Nive-AI-Lite/resolve/main/index.html
20.5 kB
| <html lang="vi"> | |
| <head> | |
| <meta charset="UTF-8"/> | |
| <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/> | |
| <title>Qwen AI</title> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet"/> | |
| <style> | |
| /* ===== RESET ===== */ | |
| *{box-sizing:border-box;margin:0;padding:0} | |
| html,body{height:100%;font-family:'Inter',sans-serif;overflow:hidden;background:#0b0917;color:#ede9fc} | |
| ::-webkit-scrollbar{width:3px}::-webkit-scrollbar-thumb{background:rgba(139,92,246,.3);border-radius:3px} | |
| /* ===== DRAWER OVERLAY ===== */ | |
| #overlay{ | |
| position:fixed;inset:0;background:rgba(0,0,0,.6); | |
| z-index:99;opacity:0;pointer-events:none; | |
| transition:opacity .2s; | |
| } | |
| #overlay.on{opacity:1;pointer-events:auto} | |
| /* ===== SIDEBAR DRAWER ===== */ | |
| #sidebar{ | |
| position:fixed;top:0;left:0;height:100%;width:270px; | |
| background:#110e21;border-right:1px solid rgba(139,92,246,.2); | |
| display:flex;flex-direction:column; | |
| z-index:100; | |
| transform:translateX(-100%); | |
| transition:transform .22s ease; | |
| } | |
| #sidebar.on{transform:translateX(0)} | |
| .sb-top{ | |
| display:flex;align-items:center;gap:10px; | |
| padding:16px 14px 12px; | |
| border-bottom:1px solid rgba(139,92,246,.15); | |
| } | |
| .q-logo{ | |
| width:34px;height:34px;border-radius:9px; | |
| background:#000;color:#fff; | |
| display:flex;align-items:center;justify-content:center; | |
| font-size:18px;font-weight:700;flex-shrink:0; | |
| } | |
| .sb-brand{flex:1} | |
| .sb-name{font-size:14px;font-weight:600} | |
| .sb-sub{font-size:11px;color:#6b5fa0;margin-top:1px} | |
| #sb-close{ | |
| width:28px;height:28px;border:none;background:none; | |
| color:#6b5fa0;font-size:18px;cursor:pointer; | |
| border-radius:6px;display:flex;align-items:center;justify-content:center; | |
| flex-shrink:0;line-height:1; | |
| } | |
| #sb-close:hover{background:rgba(139,92,246,.15);color:#ede9fc} | |
| #new-chat{ | |
| margin:12px 12px 6px;padding:10px 14px; | |
| background:linear-gradient(135deg,#8b5cf6,#3b82f6); | |
| border:none;border-radius:11px;color:#fff; | |
| font-size:13px;font-weight:500;font-family:inherit; | |
| cursor:pointer;display:flex;align-items:center;gap:6px; | |
| transition:opacity .15s; | |
| } | |
| #new-chat:hover{opacity:.85} | |
| #chat-list{flex:1;overflow-y:auto;padding:4px 8px 8px} | |
| /* chat item */ | |
| .ci{ | |
| display:flex;align-items:center;gap:8px; | |
| padding:9px 10px;border-radius:9px;cursor:pointer; | |
| margin-bottom:2px;transition:background .12s; | |
| position:relative;min-width:0; | |
| } | |
| .ci:hover,.ci.act{background:#1c1835} | |
| .ci-ico{font-size:13px;flex-shrink:0} | |
| .ci-title{font-size:13px;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0} | |
| .ci-menu{ | |
| display:none;gap:1px; | |
| background:#1c1835;border-radius:6px;padding:2px;flex-shrink:0; | |
| } | |
| .ci:hover .ci-menu{display:flex} | |
| .cm{ | |
| background:none;border:none;color:#6b5fa0; | |
| font-size:13px;cursor:pointer; | |
| width:24px;height:24px;border-radius:5px; | |
| display:flex;align-items:center;justify-content:center; | |
| } | |
| .cm:hover{background:rgba(139,92,246,.2);color:#ede9fc} | |
| .sb-foot{padding:12px;border-top:1px solid rgba(139,92,246,.15)} | |
| #reset-all{ | |
| width:100%;padding:9px;border-radius:10px;font-family:inherit; | |
| background:rgba(239,68,68,.1);border:1px solid rgba(239,68,68,.3); | |
| color:#f87171;font-size:12px;cursor:pointer; | |
| } | |
| #reset-all:hover{background:rgba(239,68,68,.2)} | |
| /* ===== MAIN — always full screen, never pushed ===== */ | |
| #main{ | |
| position:fixed;inset:0; | |
| display:flex;flex-direction:column; | |
| /* main is always underneath the drawer */ | |
| } | |
| /* ===== TOPBAR ===== */ | |
| #topbar{ | |
| height:52px;display:flex;align-items:center;gap:8px; | |
| padding:0 12px;flex-shrink:0; | |
| background:#110e21;border-bottom:1px solid rgba(139,92,246,.15); | |
| } | |
| #hamburger{ | |
| width:34px;height:34px;border:none;background:none; | |
| color:#6b5fa0;font-size:22px;cursor:pointer; | |
| border-radius:7px;display:flex;align-items:center;justify-content:center; | |
| flex-shrink:0; | |
| } | |
| #hamburger:hover{color:#ede9fc} | |
| #cur-title{flex:1;font-size:14px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} | |
| /* mode pill */ | |
| .mode-pill{ | |
| display:flex;background:#1c1835; | |
| border:1px solid rgba(139,92,246,.2);border-radius:20px;padding:3px; | |
| flex-shrink:0; | |
| } | |
| .mp{ | |
| padding:4px 11px;border-radius:16px;border:none;font-family:inherit; | |
| font-size:11px;font-weight:500;cursor:pointer; | |
| background:none;color:#6b5fa0;transition:all .15s;white-space:nowrap; | |
| } | |
| .mp.flash-on{background:#f59e0b;color:#1a0a00} | |
| .mp.pro-on{background:#8b5cf6;color:#fff} | |
| #web-toggle{ | |
| border:1px solid rgba(139,92,246,.2);background:none; | |
| border-radius:8px;padding:5px 9px;font-size:13px; | |
| color:#6b5fa0;cursor:pointer;flex-shrink:0; | |
| transition:all .15s; | |
| } | |
| #web-toggle.on{border-color:#3b82f6;color:#3b82f6;background:rgba(59,130,246,.1)} | |
| /* ===== MESSAGES ===== */ | |
| #msgs{ | |
| flex:1;overflow-y:auto; | |
| padding:20px 14px; | |
| display:flex;flex-direction:column;gap:16px; | |
| } | |
| /* welcome */ | |
| #welcome{ | |
| display:flex;flex-direction:column;align-items:center; | |
| justify-content:center;flex:1;gap:16px;text-align:center;padding:20px; | |
| } | |
| .wl{ | |
| width:62px;height:62px;border-radius:17px; | |
| background:#000;display:flex;align-items:center;justify-content:center; | |
| font-size:36px;font-weight:700;color:#fff; | |
| box-shadow:0 0 30px rgba(139,92,246,.3); | |
| } | |
| .wt{font-size:20px;font-weight:600} | |
| .ws{font-size:13px;color:#6b5fa0;max-width:260px;line-height:1.6} | |
| .sugg{display:grid;grid-template-columns:1fr 1fr;gap:7px;width:100%;max-width:320px} | |
| .sg{ | |
| background:#1c1835;border:1px solid rgba(139,92,246,.18); | |
| border-radius:10px;padding:10px 11px; | |
| font-size:12px;color:#6b5fa0; | |
| cursor:pointer;text-align:left;line-height:1.4; | |
| font-family:inherit;transition:all .15s; | |
| } | |
| .sg:hover{border-color:#8b5cf6;color:#ede9fc} | |
| /* message row */ | |
| .row{display:flex;gap:8px;animation:fadeIn .18s ease} | |
| @keyframes fadeIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}} | |
| .row.user{flex-direction:row-reverse} | |
| .av{ | |
| width:28px;height:28px;border-radius:50%;flex-shrink:0; | |
| display:flex;align-items:center;justify-content:center; | |
| font-size:13px;font-weight:700; | |
| } | |
| .row.ai .av{background:#000;color:#fff} | |
| .row.user .av{background:linear-gradient(135deg,#8b5cf6,#3b82f6);color:#fff;font-size:11px} | |
| .bub{ | |
| max-width:82%;padding:9px 13px;border-radius:14px; | |
| font-size:14px;line-height:1.65;word-break:break-word; | |
| } | |
| .row.ai .bub{background:#1c1835;border:1px solid rgba(139,92,246,.18);border-top-left-radius:3px} | |
| .row.user .bub{background:linear-gradient(135deg,#8b5cf6,#3b82f6);color:#fff;border-top-right-radius:3px} | |
| .bub img{max-width:100%;border-radius:8px;margin-top:6px;display:block} | |
| .bub code{background:rgba(255,255,255,.1);padding:1px 5px;border-radius:4px;font-size:12px} | |
| /* typing */ | |
| .typing{display:flex;gap:4px;align-items:center;padding:4px 0} | |
| .typing i{width:6px;height:6px;border-radius:50%;background:#6b5fa0;display:block;animation:bl 1.2s infinite} | |
| .typing i:nth-child(2){animation-delay:.2s} | |
| .typing i:nth-child(3){animation-delay:.4s} | |
| @keyframes bl{0%,80%,100%{opacity:.2}40%{opacity:1}} | |
| /* ===== ATTACH PREVIEW ===== */ | |
| #att-bar{ | |
| display:none;align-items:center;gap:8px; | |
| padding:6px 14px 0;font-size:12px;color:#6b5fa0; | |
| } | |
| #att-bar.on{display:flex} | |
| #att-bar img{max-height:50px;border-radius:6px} | |
| #att-bar span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} | |
| #att-rm{background:none;border:none;color:#6b5fa0;font-size:16px;cursor:pointer;padding:2px} | |
| /* ===== INPUT BAR ===== */ | |
| #inp-bar{ | |
| padding:10px 12px 18px;flex-shrink:0; | |
| background:#0b0917; | |
| } | |
| .inp-box{ | |
| display:flex;align-items:flex-end;gap:6px; | |
| background:#1a1530;border:1px solid rgba(139,92,246,.2); | |
| border-radius:16px;padding:7px 8px; | |
| } | |
| .inp-box:focus-within{border-color:rgba(139,92,246,.5)} | |
| #txt{ | |
| flex:1;background:none;border:none;outline:none; | |
| color:#ede9fc;font-size:14px;font-family:inherit; | |
| resize:none;max-height:110px;line-height:1.5;padding:4px 2px; | |
| } | |
| #txt::placeholder{color:#4a4065} | |
| .ib{ | |
| background:none;border:none;cursor:pointer;color:#6b5fa0; | |
| font-size:20px;padding:3px;border-radius:7px; | |
| display:flex;align-items:center;flex-shrink:0; | |
| } | |
| .ib:hover{color:#8b5cf6} | |
| #send{ | |
| width:32px;height:32px;border-radius:9px;flex-shrink:0; | |
| background:linear-gradient(135deg,#8b5cf6,#3b82f6); | |
| border:none;color:#fff;font-size:15px;cursor:pointer; | |
| display:flex;align-items:center;justify-content:center; | |
| } | |
| #send:disabled{opacity:.3;cursor:default} | |
| #finput{display:none} | |
| /* ===== MODAL ===== */ | |
| #mdl-bg{ | |
| display:none;position:fixed;inset:0; | |
| background:rgba(0,0,0,.65);z-index:200; | |
| align-items:center;justify-content:center; | |
| } | |
| #mdl-bg.on{display:flex} | |
| #mdl{ | |
| background:#110e21;border:1px solid rgba(139,92,246,.25); | |
| border-radius:16px;padding:22px;width:280px; | |
| display:flex;flex-direction:column;gap:13px; | |
| } | |
| #mdl h3{font-size:14px;font-weight:600} | |
| #rn{ | |
| width:100%;background:#1a1530;border:1px solid rgba(139,92,246,.2); | |
| border-radius:9px;padding:9px 12px;color:#ede9fc; | |
| font-size:14px;outline:none;font-family:inherit; | |
| } | |
| #rn:focus{border-color:#8b5cf6} | |
| .mdl-btns{display:flex;gap:8px} | |
| .mdl-btns button{ | |
| flex:1;padding:9px;border-radius:9px;font-size:13px; | |
| font-weight:500;cursor:pointer;font-family:inherit;border:none; | |
| } | |
| #mdl-ok{background:#8b5cf6;color:#fff} | |
| #mdl-cancel{background:#1c1835;color:#6b5fa0;border:1px solid rgba(139,92,246,.2)} | |
| </style> | |
| </head> | |
| <body> | |
| <!-- OVERLAY --> | |
| <div id="overlay" onclick="closeSB()"></div> | |
| <!-- ===== SIDEBAR ===== --> | |
| <nav id="sidebar"> | |
| <div class="sb-top"> | |
| <div class="q-logo">Q</div> | |
| <div class="sb-brand"> | |
| <div class="sb-name">Qwen AI</div> | |
| <div class="sb-sub">Trợ lý thông minh</div> | |
| </div> | |
| <button id="sb-close" onclick="closeSB()">✕</button> | |
| </div> | |
| <button id="new-chat" onclick="doNew()">✦ Cuộc trò chuyện mới</button> | |
| <div id="chat-list"></div> | |
| <div class="sb-foot"> | |
| <button id="reset-all" onclick="doReset()">🗑 Xóa toàn bộ dữ liệu</button> | |
| </div> | |
| </nav> | |
| <!-- ===== MAIN ===== --> | |
| <div id="main"> | |
| <div id="topbar"> | |
| <button id="hamburger" onclick="openSB()">☰</button> | |
| <div id="cur-title">Qwen AI</div> | |
| <div class="mode-pill"> | |
| <button class="mp flash-on" id="mflash" onclick="setMode('flash')">⚡ Flash</button> | |
| <button class="mp" id="mpro" onclick="setMode('pro')">✦ Pro</button> | |
| </div> | |
| <button id="web-toggle" onclick="toggleWeb()" title="Tìm kiếm web">🌐</button> | |
| </div> | |
| <div id="msgs"></div> | |
| <div id="att-bar"> | |
| <span id="att-name"></span> | |
| <button id="att-rm" onclick="rmAtt()">✕</button> | |
| </div> | |
| <div id="inp-bar"> | |
| <div class="inp-box"> | |
| <input type="file" id="finput" accept="image/*,video/*,audio/*,.txt,.md,.csv" onchange="onFile(this)"/> | |
| <button class="ib" onclick="doCamera()" title="Chụp ảnh">📷</button> | |
| <button class="ib" onclick="document.getElementById('finput').click()" title="Đính kèm">➕</button> | |
| <textarea id="txt" rows="1" placeholder="Nhắn tin..." oninput="grow(this)" onkeydown="onKey(event)"></textarea> | |
| <button id="send" onclick="doSend()">➤</button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- RENAME MODAL --> | |
| <div id="mdl-bg" onclick="mdlBg(event)"> | |
| <div id="mdl"> | |
| <h3>Đặt tên cuộc trò chuyện</h3> | |
| <input id="rn" type="text" maxlength="40" placeholder="Nhập tên..." onkeydown="rnKey(event)"/> | |
| <div class="mdl-btns"> | |
| <button id="mdl-cancel" onclick="closeMdl()">Hủy</button> | |
| <button id="mdl-ok" onclick="doRnSave()">Lưu</button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| /* ─── STATE ─── */ | |
| const SK='qwenai_v3'; | |
| let G={chats:{},order:[],cur:null,mode:'flash',web:false}; | |
| let rnId=null, attFile=null; | |
| function save(){try{localStorage.setItem(SK,JSON.stringify(G))}catch(e){}} | |
| function load(){ | |
| try{const d=JSON.parse(localStorage.getItem(SK)||'{}');if(d&&d.chats)G=d}catch(e){} | |
| } | |
| /* ─── SIDEBAR ─── */ | |
| function openSB(){ | |
| document.getElementById('sidebar').classList.add('on'); | |
| document.getElementById('overlay').classList.add('on'); | |
| } | |
| function closeSB(){ | |
| document.getElementById('sidebar').classList.remove('on'); | |
| document.getElementById('overlay').classList.remove('on'); | |
| } | |
| /* ─── CHATS ─── */ | |
| function uid(){return 'c'+Date.now()+Math.random().toString(36).slice(2,5)} | |
| function doNew(){ | |
| const id=uid(); | |
| G.chats[id]={id,name:'Cuộc trò chuyện',msgs:[],pinned:false}; | |
| // insert after pinned | |
| const pinned=G.order.filter(x=>G.chats[x]?.pinned); | |
| const rest=G.order.filter(x=>G.chats[x]&&!G.chats[x].pinned); | |
| G.order=[...pinned,id,...rest]; | |
| G.cur=id; | |
| save();render();closeSB(); | |
| } | |
| function pickChat(id){ | |
| G.cur=id;save();render();closeSB(); | |
| } | |
| function delChat(id,e){ | |
| e&&e.stopPropagation(); | |
| if(!confirm('Xóa cuộc trò chuyện này?'))return; | |
| delete G.chats[id]; | |
| G.order=G.order.filter(x=>x!==id); | |
| if(G.cur===id)G.cur=G.order[0]||null; | |
| save();render(); | |
| } | |
| function pinChat(id,e){ | |
| e&&e.stopPropagation(); | |
| const c=G.chats[id];if(!c)return; | |
| c.pinned=!c.pinned; | |
| const p=G.order.filter(x=>G.chats[x]?.pinned); | |
| const r=G.order.filter(x=>G.chats[x]&&!G.chats[x].pinned); | |
| G.order=[...p,...r]; | |
| save();renderSB(); | |
| } | |
| function addMsg(id,role,content){ | |
| if(!G.chats[id])return; | |
| G.chats[id].msgs.push({role,content}); | |
| // auto-name | |
| const um=G.chats[id].msgs.filter(m=>m.role==='user'); | |
| if(um.length===1&&role==='user'){ | |
| const t=String(content).replace(/<[^>]+>/g,'').trim().slice(0,28); | |
| if(t){G.chats[id].name=t;renderSB();} | |
| } | |
| save(); | |
| } | |
| /* ─── RENDER ─── */ | |
| function render(){renderSB();renderChat();} | |
| function renderSB(){ | |
| const list=document.getElementById('chat-list'); | |
| list.innerHTML=''; | |
| G.order.forEach(id=>{ | |
| const c=G.chats[id];if(!c)return; | |
| const el=document.createElement('div'); | |
| el.className='ci'+(id===G.cur?' act':''); | |
| el.innerHTML= | |
| `<span class="ci-ico">${c.pinned?'📌':'💬'}</span>`+ | |
| `<span class="ci-title">${esc(c.name)}</span>`+ | |
| `<div class="ci-menu">`+ | |
| `<button class="cm" onclick="openRn(event,'${id}')" title="Đổi tên">✏️</button>`+ | |
| `<button class="cm" onclick="pinChat('${id}',event)" title="${c.pinned?'Bỏ ghim':'Ghim'}">${c.pinned?'🔖':'📍'}</button>`+ | |
| `<button class="cm" onclick="delChat('${id}',event)" title="Xóa">🗑</button>`+ | |
| `</div>`; | |
| el.onclick=()=>pickChat(id); | |
| list.appendChild(el); | |
| }); | |
| } | |
| const WELCOME_HTML=`<div id="welcome"> | |
| <div class="wl">Q</div> | |
| <div class="wt">Xin chào! Tôi là Qwen AI</div> | |
| <div class="ws">Hỏi bất cứ điều gì — phân tích ảnh, tìm kiếm web, hoặc trò chuyện.</div> | |
| <div class="sugg"> | |
| <button class="sg" onclick="useSug(this)">💡 Giải thích một khái niệm</button> | |
| <button class="sg" onclick="useSug(this)">🖼 Phân tích ảnh tôi gửi</button> | |
| <button class="sg" onclick="useSug(this)">✍️ Viết email chuyên nghiệp</button> | |
| <button class="sg" onclick="useSug(this)">🔍 Tìm thông tin mới nhất</button> | |
| </div> | |
| </div>`; | |
| function showWelcome(){ | |
| document.getElementById('msgs').innerHTML=WELCOME_HTML; | |
| } | |
| function renderChat(){ | |
| const area=document.getElementById('msgs'); | |
| const titleEl=document.getElementById('cur-title'); | |
| if(!G.cur||!G.chats[G.cur]){ | |
| showWelcome(); | |
| titleEl.textContent='Qwen AI'; | |
| return; | |
| } | |
| const c=G.chats[G.cur]; | |
| titleEl.textContent=c.name; | |
| if(c.msgs.length===0){ | |
| showWelcome(); | |
| return; | |
| } | |
| area.innerHTML=''; | |
| c.msgs.forEach(m=>addBubble(m.role,m.content,false)); | |
| area.scrollTop=area.scrollHeight; | |
| } | |
| function addBubble(role,content,scroll=true){ | |
| const area=document.getElementById('msgs'); | |
| // clear welcome if present | |
| if(document.getElementById('welcome'))area.innerHTML=''; | |
| const row=document.createElement('div'); | |
| row.className='row '+role; | |
| row.innerHTML=`<div class="av">${role==='ai'?'Q':'👤'}</div><div class="bub">${fmt(content)}</div>`; | |
| area.appendChild(row); | |
| if(scroll)area.scrollTop=area.scrollHeight; | |
| return row; | |
| } | |
| function fmt(t){ | |
| t=String(t); | |
| t=t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1"/>'); | |
| t=t.replace(/\*\*([^*]+)\*\*/g,'<strong>$1</strong>'); | |
| t=t.replace(/\*([^*]+)\*/g,'<em>$1</em>'); | |
| t=t.replace(/`([^`]+)`/g,'<code>$1</code>'); | |
| t=t.replace(/\n/g,'<br>'); | |
| return t; | |
| } | |
| function esc(s){return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"')} | |
| /* ─── SEND ─── */ | |
| async function doSend(){ | |
| const t=document.getElementById('txt'); | |
| const prompt=t.value.trim(); | |
| if(!prompt&&!attFile)return; | |
| if(!G.cur)doNew(); | |
| const cid=G.cur; | |
| const disp=prompt+(attFile?` <em>[📎 ${esc(attFile.name)}]</em>`:''); | |
| addBubble('user',disp); | |
| addMsg(cid,'user',disp); | |
| t.value='';t.style.height=''; | |
| document.getElementById('send').disabled=true; | |
| const tw=addBubble('ai',''); | |
| tw.querySelector('.bub').innerHTML='<div class="typing"><i></i><i></i><i></i></div>'; | |
| try{ | |
| const fd=new FormData(); | |
| fd.append('prompt',prompt); | |
| fd.append('mode',G.mode); | |
| fd.append('web_search',G.web?'true':'false'); | |
| fd.append('history',JSON.stringify((G.chats[cid]?.msgs||[]).slice(-4))); | |
| if(attFile)fd.append('file',attFile); | |
| const r=await fetch('/api/chat',{method:'POST',body:fd}); | |
| const d=await r.json(); | |
| const reply=d.status==='success'?d.response:`❌ Lỗi: ${d.message}`; | |
| tw.querySelector('.bub').innerHTML=fmt(reply); | |
| addMsg(cid,'ai',reply); | |
| }catch(e){ | |
| tw.querySelector('.bub').innerHTML='❌ Không kết nối được server.'; | |
| } | |
| document.getElementById('send').disabled=false; | |
| document.getElementById('msgs').scrollTop=99999; | |
| rmAtt(); | |
| } | |
| function useSug(btn){document.getElementById('txt').value=btn.textContent.replace(/^[^\s]+\s/,'').trim();doSend();} | |
| function onKey(e){if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();doSend();}} | |
| function grow(ta){ta.style.height='auto';ta.style.height=Math.min(ta.scrollHeight,110)+'px';} | |
| /* ─── MODE / WEB ─── */ | |
| function setMode(m){ | |
| G.mode=m;save(); | |
| document.getElementById('mflash').className='mp'+(m==='flash'?' flash-on':''); | |
| document.getElementById('mpro').className='mp'+(m==='pro'?' pro-on':''); | |
| } | |
| function toggleWeb(){ | |
| G.web=!G.web;save(); | |
| document.getElementById('web-toggle').classList.toggle('on',G.web); | |
| } | |
| /* ─── FILE ─── */ | |
| function onFile(inp){ | |
| const f=inp.files[0];if(!f)return; | |
| attFile=f; | |
| const bar=document.getElementById('att-bar'); | |
| document.getElementById('att-name').textContent=f.name; | |
| bar.querySelectorAll('img').forEach(i=>i.remove()); | |
| if(f.type.startsWith('image/')){ | |
| const r=new FileReader(); | |
| r.onload=e=>{const img=document.createElement('img');img.src=e.target.result;bar.insertBefore(img,document.getElementById('att-name'));}; | |
| r.readAsDataURL(f); | |
| } | |
| bar.classList.add('on'); | |
| } | |
| function rmAtt(){ | |
| attFile=null; | |
| document.getElementById('att-bar').classList.remove('on'); | |
| document.getElementById('att-bar').querySelectorAll('img').forEach(i=>i.remove()); | |
| document.getElementById('finput').value=''; | |
| } | |
| function doCamera(){ | |
| const inp=document.getElementById('finput'); | |
| inp.accept='image/*';inp.setAttribute('capture','environment'); | |
| inp.click();setTimeout(()=>inp.removeAttribute('capture'),500); | |
| } | |
| /* ─── RENAME ─── */ | |
| function openRn(e,id){ | |
| e.stopPropagation();rnId=id; | |
| document.getElementById('rn').value=G.chats[id]?.name||''; | |
| document.getElementById('mdl-bg').classList.add('on'); | |
| setTimeout(()=>document.getElementById('rn').focus(),60); | |
| } | |
| function closeMdl(){document.getElementById('mdl-bg').classList.remove('on');rnId=null;} | |
| function mdlBg(e){if(e.target===document.getElementById('mdl-bg'))closeMdl();} | |
| function rnKey(e){if(e.key==='Enter')doRnSave();if(e.key==='Escape')closeMdl();} | |
| function doRnSave(){ | |
| const v=document.getElementById('rn').value.trim(); | |
| if(v&&rnId&&G.chats[rnId]){ | |
| G.chats[rnId].name=v;save();renderSB(); | |
| if(rnId===G.cur)document.getElementById('cur-title').textContent=v; | |
| } | |
| closeMdl(); | |
| } | |
| /* ─── RESET ─── */ | |
| function doReset(){ | |
| if(!confirm('Xóa toàn bộ? Không thể hoàn tác.'))return; | |
| G={chats:{},order:[],cur:null,mode:G.mode,web:G.web}; | |
| save();render(); | |
| } | |
| /* ─── INIT ─── */ | |
| load(); | |
| setMode(G.mode||'flash'); | |
| if(G.web)document.getElementById('web-toggle').classList.add('on'); | |
| render(); | |
| // Nếu chưa có chat nào thì hiện welcome | |
| if(!G.cur)showWelcome(); | |
| </script> | |
| </body> | |
| </html> | |