README
}
function addMsg(role, html){ var d = document.createElement("div"); d.className = "msg " + (role==="user"?"user":"bot"); d.innerHTML = (role==="user"?"":'
function hero(){ chat.innerHTML = ""; var h = document.createElement("div"); h.className = "hero"; h.innerHTML = '
สวัสดี ฉันคือ Zee Hub
บอกฉันว่าอยากได้สคริปต์อะไร แล้วฉันจะเขียนโค้ดที่ใช้งานได้จริงให้ พร้อมปุ่มคัดลอก
'; SUGG.forEach(function(s){ var b = document.createElement("button"); b.className = "chip"; b.textContent = s; b.onclick = function(){ inp.value = s; go(); }; h.querySelector(".chips").appendChild(b); }); chat.appendChild(h); }async function go(){
var q = inp.value.trim();
if(!q || busy) return;
if(!sample){ try{ sample = await claude.use("sample"); }catch(e){} }
var h = chat.querySelector(".hero"); if(h) chat.innerHTML = "";
inp.value = ""; inp.style.height = "auto";
addMsg("user", esc(q).replace(/\n/g,"
"));
if(!sample){ addMsg("bot", 'ตอนนี้ยังเชื่อมต่อ AI ไม่ได้ กรุณาเปิดหน้านี้ผ่านลิงก์ที่แชร์ในแอป Claude แล้วลองใหม่'); return; }
history.push({role:"user", content:q});
busy = true; sendBtn.disabled = true;
var bub = addMsg("bot", '
'+m+'
'; history.pop(); } busy = false; sendBtn.disabled = false; inp.focus(); chat.scrollTop = chat.scrollHeight; }chat.addEventListener("click", async function(ev){ var b = ev.target.closest("button[data-act]"); if(!b) return; var code = codeStore[+b.dataset.id]; if(b.dataset.act==="copy"){ var ok = false; try{ await navigator.clipboard.writeText(code); ok = true; }catch(e){ try{ var t = document.createElement("textarea"); t.value = code; document.body.appendChild(t); t.select(); ok = document.execCommand("copy"); t.remove(); }catch(e2){} } b.textContent = ok ? "คัดลอกแล้ว ✓" : "คัดลอกไม่ได้"; b.classList.toggle("ok", ok); setTimeout(function(){ b.textContent = "คัดลอก"; b.classList.remove("ok"); }, 1800); } else if(b.dataset.act==="save" && downloads){ try{ await downloads.save({filename:"zee-hub-script."+(EXT[b.dataset.lang]||"txt"), data:code}); }catch(e){} } });
sendBtn.onclick = go; inp.addEventListener("keydown", function(e){ if(e.key==="Enter" && !e.shiftKey && !e.isComposing){ e.preventDefault(); go(); }}); inp.addEventListener("input", function(){ inp.style.height = "auto"; inp.style.height = Math.min(inp.scrollHeight,140)+"px"; }); document.getElementById("clear").onclick = function(){ if(busy) return; history = []; codeStore = []; hero(); };
hero(); try{ claude.use("downloads").then(function(d){ downloads = d; }).catch(function(){}); }catch(e){} try{ claude.use("sample").then(function(s){ sample = s; }).catch(function(){}); }catch(e){} })();