Repository navigation
Expand file tree
/
Copy pathmbcode.html
More file actions
325 lines (316 loc) · 31 KB
/
Copy pathmbcode.html
File metadata and controls
325 lines (316 loc) · 31 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html lang="he" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MBbot code</title>
<style>
:root{--w:#ffb454;--e:#ff6b81}
:root,[data-th=aurora]{--bg:#0b0d14;--p:#12151f;--p2:#191d2b;--b:#262b3d;--t:#e8eaf3;--m:#8b92ab;--a:#7c6cff;--a2:#38d6c4;--g:#5b8cff}
[data-th=ocean]{--bg:#06141d;--p:#0b1f2c;--p2:#102a3b;--b:#1b3b50;--t:#e6f4fb;--m:#7fa3b8;--a:#18a0fb;--a2:#2de2c2;--g:#0b6bcb}
[data-th=sunset]{--bg:#150c14;--p:#1e121d;--p2:#2a1829;--b:#3d2339;--t:#fdeef0;--m:#b58a9a;--a:#ff6b6b;--a2:#ffb454;--g:#e0409a}
[data-th=light]{--bg:#f4f5fb;--p:#fff;--p2:#eef0f8;--b:#dcdfee;--t:#1b1e2e;--m:#6a7090;--a:#6a5cff;--a2:#0aa89a;--g:#3d7bff}
*{box-sizing:border-box}html,body{height:100%;margin:0}
body{background:var(--bg);color:var(--t);font:15px/1.5 system-ui,"Segoe UI",Arial,sans-serif;display:flex;flex-direction:column}
header{display:flex;align-items:center;gap:10px;padding:10px 16px;border-bottom:1px solid var(--b);background:var(--p)}
header h1{font-size:17px;margin:0;background:linear-gradient(90deg,var(--a),var(--a2));-webkit-background-clip:text;background-clip:text;color:transparent}
.sp{flex:1}
button,select,input,textarea{font:inherit;color:inherit}
.btn{background:var(--p2);border:1px solid var(--b);padding:6px 12px;border-radius:9px;cursor:pointer}
.btn:hover{border-color:var(--a)}.btn.pri{background:linear-gradient(135deg,var(--a),var(--g));border:0;font-weight:600}
.btn:disabled{opacity:.5;cursor:not-allowed}
main{flex:1;display:grid;grid-template-columns:380px 1fr;min-height:0}
#chat{display:flex;flex-direction:column;border-inline-end:1px solid var(--b);min-height:0;background:var(--p)}
#msgs{flex:1;overflow:auto;padding:14px;display:flex;flex-direction:column;gap:10px}
.m{padding:10px 13px;border-radius:14px;max-width:94%;white-space:pre-wrap;word-break:break-word}
.u{background:var(--a);align-self:flex-start;border-end-start-radius:4px}
.ai{background:var(--p2);border:1px solid var(--b);align-self:flex-end;border-end-end-radius:4px}
.n{align-self:center;font-size:13px;color:var(--w);background:#ffb4541a;border:1px solid #ffb45440}
.er{align-self:center;color:var(--e);background:#ff6b811a;border:1px solid #ff6b8140}
.tag{display:inline-block;margin-top:6px;font-size:11px;color:var(--a2);background:#38d6c41a;padding:1px 8px;border-radius:99px;direction:ltr}
.chips{display:flex;flex-wrap:wrap;gap:6px;padding:0 14px 8px}
.chip{font-size:12.5px;padding:4px 10px;border-radius:99px;border:1px solid var(--b);background:transparent;cursor:pointer;color:var(--m)}
.chip:hover{color:var(--t);border-color:var(--a)}
#in{display:flex;gap:8px;padding:12px;border-top:1px solid var(--b)}
#in textarea{flex:1;resize:none;height:62px;background:var(--bg);border:1px solid var(--b);border-radius:11px;padding:8px 10px}
#in textarea:focus{outline:0;border-color:var(--a)}
#cv{display:flex;flex-direction:column;min-width:0;min-height:0}
.bar{display:flex;align-items:center;gap:8px;padding:8px 12px;border-bottom:1px solid var(--b);flex-wrap:wrap;background:var(--p)}
.tabs{display:flex;background:var(--bg);border:1px solid var(--b);border-radius:9px;overflow:hidden}
.tabs button{background:none;border:0;padding:5px 14px;cursor:pointer;color:var(--m)}
.tabs button.on{background:var(--p2);color:var(--t)}
.bar select{background:var(--bg);border:1px solid var(--b);border-radius:8px;padding:5px 8px}
#stage{flex:1;min-height:0;position:relative;background:repeating-conic-gradient(var(--p) 0 25%,var(--bg) 0 50%) 0 0/20px 20px;overflow:auto;display:flex;justify-content:center}
#fr{border:0;background:#fff;width:100%;height:100%;transition:width .25s}
#code{display:none;flex:1;min-height:0}
#files{width:170px;border-inline-end:1px solid var(--b);overflow:auto;background:var(--p)}
#files div{padding:7px 12px;cursor:pointer;font-size:13px;direction:ltr;text-align:left;color:var(--m)}
#files div.on{background:var(--p2);color:var(--t)}
#ed{flex:1;background:var(--bg);border:0;padding:14px;direction:ltr;text-align:left;font:13px/1.55 ui-monospace,Consolas,monospace;resize:none;tab-size:2;white-space:pre}
#ed:focus{outline:0}
.empty{margin:auto;text-align:center;color:var(--m);padding:20px}
.empty b{display:block;font-size:20px;color:var(--t);margin-bottom:6px}
dialog{background:var(--p);color:var(--t);border:1px solid var(--b);border-radius:16px;padding:20px;width:min(460px,92vw)}
dialog::backdrop{background:#000a}
dialog label{display:block;margin:12px 0 4px;font-size:13px;color:var(--m)}
dialog input{width:100%;background:var(--bg);border:1px solid var(--b);border-radius:9px;padding:8px;direction:ltr}
.dots span{animation:b 1s infinite;display:inline-block}.dots span:nth-child(2){animation-delay:.15s}.dots span:nth-child(3){animation-delay:.3s}
@keyframes b{50%{transform:translateY(-4px);opacity:.4}}
@media(max-width:820px){main{grid-template-columns:1fr;grid-template-rows:55% 45%}#files{width:110px}}
body{background:radial-gradient(900px 500px at 85% -10%,color-mix(in srgb,var(--a) 24%,transparent),transparent),radial-gradient(700px 420px at -10% 110%,color-mix(in srgb,var(--a2) 18%,transparent),transparent),var(--bg)}
header,#chat,.bar{background:color-mix(in srgb,var(--p) 78%,transparent);backdrop-filter:blur(14px)}
header{flex-wrap:wrap}header small{display:block;color:var(--m);font-size:11.5px;margin-top:-2px}
#logo{display:flex;cursor:pointer;filter:drop-shadow(0 4px 14px color-mix(in srgb,var(--a) 55%,transparent));transition:transform .2s}#logo:hover{transform:rotate(-6deg) scale(1.06)}
.btn{transition:.15s}.btn.pri:hover{filter:brightness(1.12)}
.u{color:#fff;background:linear-gradient(135deg,var(--a),var(--g))}
.m{animation:in .3s}@keyframes in{from{opacity:0;transform:translateY(6px)}}
.who{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--m);margin-bottom:6px;font-weight:600}
.sw{width:20px;height:20px;border-radius:50%;border:2px solid var(--b);cursor:pointer;padding:0;margin:0 2px}.sw.on{border-color:var(--t);transform:scale(1.15)}
#in{flex-wrap:wrap}#in textarea{min-width:0}
#st{width:100%;background:var(--bg);border:1px solid var(--b);border-radius:9px;padding:5px 8px}
</style>
</head>
<body>
<header>
<div id="logo" title="תמונות פרופיל"></div>
<div><h1>MBbot code</h1><small>עוזר קוד שבונה אתרים בשניות</small></div><span class="sp"></span>
<span id="sws"></span>
<button class="btn" id="lg">EN</button>
<button class="btn" id="undo" title="גרסה קודמת">↶</button>
<button class="btn" id="reset">חדש</button>
<button class="btn" id="cfgb">⚙ הגדרות</button>
</header>
<main>
<section id="chat">
<div id="msgs"></div>
<div class="chips" id="chips"></div>
<div id="in"><select id="st"><option value="">סגנון: חופשי</option><option value="minimalist, airy, lots of whitespace, refined typography">מינימליסטי</option><option value="glassmorphism, translucent layers, soft gradients, blur">זכוכית</option><option value="neo-brutalist, bold borders, hard shadows, loud colors">ניאו-ברוטליסט</option><option value="dark luxury, gold accents, serif display type, cinematic">יוקרתי כהה</option><option value="playful, colorful, rounded shapes, fun micro-animations">משחקי</option></select><textarea id="q" placeholder="תארו את האתר שתרצו, או מה לשנות בו..."></textarea><button class="btn" id="mic" title="הקלטה קולית">🎤</button><button class="btn pri" id="send">שלח</button></div>
</section>
<section id="cv">
<div class="bar">
<div class="tabs"><button id="t1" class="on">תצוגה</button><button id="t2">קוד</button></div>
<select id="pg" title="עמוד"></select>
<select id="dv"><option value="100%">מחשב</option><option value="820px">טאבלט</option><option value="390px">נייד</option></select>
<span class="sp"></span>
<button class="btn" id="fs" title="מסך מלא">⛶</button><button class="btn" id="cp">העתק</button>
<button class="btn" id="nt">חלון חדש</button>
<button class="btn pri" id="zip">הורד ZIP</button>
</div>
<div id="stage"><div class="empty" id="emp"><b>הקנבס ריק</b>כתבו בצ'אט איזה אתר לבנות, והוא יופיע כאן עם תצוגה מקדימה חיה.</div><iframe id="fr" sandbox="allow-scripts allow-forms allow-modals" hidden></iframe></div>
<div id="code"><div id="files"></div><textarea id="ed" spellcheck="false"></textarea></div>
</section>
</main>
<dialog id="dlg">
<h3 style="margin:0 0 4px">הגדרות</h3>
<label>מפתח API של Google AI Studio</label><input id="k" type="password" placeholder="AIza...">
<label>מודל ראשי</label><input id="mdl" placeholder="gemini-3.8-flash">
<label>מודלים חלופיים (עד 3, מופרדים בפסיק). ריק = זיהוי אוטומטי מהחשבון</label><input id="fb" placeholder="gemini-2.5-flash, gemini-2.0-flash">
<div style="margin-top:12px"><button class="btn" id="tst" type="button">בדיקת חיבור</button> <span id="tr" style="font-size:13px;color:var(--m)"></span></div>
<p style="font-size:12px;color:var(--m)">המפתח נשמר בדפדפן שלכם בלבד ונשלח רק ל-Google.</p>
<div style="display:flex;gap:8px;justify-content:flex-end"><button class="btn" id="cl">סגור</button><button class="btn pri" id="sv">שמור</button></div>
</dialog>
<dialog id="av"><h3 style="margin:0 0 12px">תמונות פרופיל של MBbot code</h3><div id="avg" style="display:grid;grid-template-columns:1fr 1fr;gap:14px"></div><div style="text-align:end;margin-top:14px"><button class="btn" id="avc">סגור</button></div></dialog>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script>
const $=s=>document.querySelector(s),sleep=ms=>new Promise(r=>setTimeout(r,ms));
let cfg={key:'',model:'gemini-3.8-flash',fb:''};
try{Object.assign(cfg,JSON.parse(localStorage.getItem('cfg')||'{}'))}catch(e){}
let files={},hist=[],vers=[],cur='index.html',page='index.html',busy=false;
const SYS=`You are MBbot code, an elite senior front-end engineer and award-winning UI/UX designer. You build complete, production-grade multi-page websites.
RULES:
- Reply in the user's language. Start with a brief plan (2-4 short lines: pages, design direction, palette, key features). No long explanations.
- Output every created/changed file in EXACTLY this format, with the full file content (never partial snippets, never markdown fences):
<<<FILE:index.html>>>
...content...
<<<END>>>
- Only static HTML/CSS/vanilla JS. Pages are separate .html files that link to each other with relative links (href="about.html"), sharing one style.css and optional script.js. Link them with <link rel="stylesheet" href="style.css"> and <script src="script.js"><\/script>.
- Design quality: distinctive art direction, not a generic template. Strong typographic hierarchy (Google Fonts allowed), a cohesive CSS-variable palette, generous spacing, modern layout (grid/flex), smooth micro-interactions, scroll reveals, hover states, gradients/glass/shadows used with taste, fully responsive, accessible (semantic HTML, contrast, alt text, focus states), dark/light friendly. Use inline SVG or CSS art or gradients for visuals; use https://picsum.photos only if photos are essential. Realistic, well-written copy in the user's language (RTL when Hebrew/Arabic), never lorem ipsum.
- Include working JS where relevant (menus, tabs, forms validation, filters, carousels, counters, theme toggle).
- When the user asks for edits, return only the files that changed, in full. Keep everything else consistent.
- Think about edge cases and make the result feel finished and polished.`;
const NAV='<script>('+(function(){document.addEventListener('click',function(e){var a=e.target.closest&&e.target.closest('a[href]');if(!a)return;var h=a.getAttribute('href');if(/^(https?:|mailto:|tel:|#|javascript:)/.test(h))return;e.preventDefault();parent.postMessage({nav:h.split('#')[0].replace(/^\.?\//,'')},'*')})}).toString()+')()<\/script>';
function add(cls,txt,tag){const d=document.createElement('div');const g=/\bg\b/.test(cls);d.className='m '+cls;d.textContent=g?txt:T(txt);if(/\bai\b/.test(cls)){const h=document.createElement('div');h.className='who';h.innerHTML=AVS()+'MBbot code';d.prepend(h)}if(tag){const t=document.createElement('div');t.className='tag';t.textContent=T(tag);d.append(t)}$('#msgs').append(d);$('#msgs').scrollTop=1e9;return d}
const norm=f=>f.replace(/^\.?\//,'');
function build(p){
let h=files[p]||'';
h=h.replace(/<link[^>]*href=["']([^"']+\.css)["'][^>]*>/gi,(m,f)=>files[norm(f)]!=null?'<style>'+files[norm(f)]+'</style>':m);
h=h.replace(/<script([^>]*)src=["']([^"']+\.js)["']([^>]*)><\/script>/gi,(m,a,f,b)=>files[norm(f)]!=null?'<script'+a+b+'>'+files[norm(f)]+'<\/script>':m);
return /<head[^>]*>/i.test(h)?h.replace(/<head[^>]*>/i,m=>m+NAV):NAV+h;
}
function refresh(keepEd){
const names=Object.keys(files),has=names.length>0;
$('#emp').style.display=has?'none':'';$('#fr').hidden=!has;
const pages=names.filter(n=>n.endsWith('.html'));
if(!pages.includes(page))page=pages[0]||'';
$('#pg').innerHTML=pages.map(p=>`<option ${p==page?'selected':''}>${p}</option>`).join('');
if(has&&page)$('#fr').srcdoc=build(page);
if(!files[cur])cur=names[0];
$('#files').innerHTML='';names.forEach(n=>{const d=document.createElement('div');d.textContent=n;d.className=n==cur?'on':'';d.onclick=()=>{cur=n;refresh()};$('#files').append(d)});
if(!keepEd)$('#ed').value=files[cur]||'';
$('#undo').disabled=!vers.length;save();
}
function parse(t){const out={};t.replace(/<<<FILE:\s*(.+?)\s*>>>\r?\n?([\s\S]*?)(?:<<<END>>>|(?=<<<FILE:)|$)/g,(m,n,c)=>{out[norm(n.trim())]=c.replace(/^```\w*\n/,'').replace(/\n```\s*$/,'').trim()+'\n';return m});return out}
const gf=async(u,o)=>{try{return await fetch(u,o)}catch(e){throw{status:0,net:true,msg:"network"}}};
const lim={};
async function maxTok(m){
if(lim[m])return lim[m];
try{
const r=await gf('https://generativelanguage.googleapis.com/v1beta/models/'+encodeURIComponent(m),{headers:{'x-goog-api-key':cfg.key}});
if(r.status==404)throw{status:404,msg:'model not found'};
const j=await r.json();return lim[m]=Math.min(j.outputTokenLimit||8192,65536);
}catch(e){if(e.status==404)throw e;return 8192}
}
async function call(model,contents){
const mt=await maxTok(model);
const r=await gf(`https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(model)}:generateContent`,{method:'POST',headers:{'Content-Type':'application/json','x-goog-api-key':cfg.key},
body:JSON.stringify({systemInstruction:{parts:[{text:SYS}]},contents,generationConfig:{temperature:0.9,maxOutputTokens:mt}})});
const j=await r.json().catch(()=>({}));
if(!r.ok)throw{status:r.status,msg:(j.error&&j.error.message)||r.statusText,st:(j.error&&j.error.status)||''};
const c=j.candidates&&j.candidates[0];
const txt=c&&c.content&&c.content.parts?c.content.parts.map(p=>p.text||'').join(''):'';
if(!txt)throw{status:0,msg:'התקבלה תשובה ריקה'+(j.promptFeedback?' (נחסם)':'')};
return {text:txt,fr:c&&c.finishReason};
}
const isBusy=e=>[429,500,503,504].includes(e.status)||/overload|unavailable|exhausted/i.test((e.msg||'')+(e.st||''));
async function autoFb(){
try{const r=await gf('https://generativelanguage.googleapis.com/v1beta/models?pageSize=200',{headers:{'x-goog-api-key':cfg.key}});const j=await r.json();
return (j.models||[]).filter(m=>/flash/i.test(m.name)&&(m.supportedGenerationMethods||[]).includes('generateContent')&&!/image|tts|live|audio|embed|thinking-exp/i.test(m.name))
.map(m=>m.name.replace('models/','')).filter(n=>n!==cfg.model).sort().reverse().slice(0,3)}catch(e){return[]}
}
async function gen(contents){
let skipToFb=false;
for(let i=0;i<=2&&!skipToFb;i++){
try{return{...await call(cfg.model,contents),model:cfg.model}}
catch(e){
if(e.status==404){add('n','המודל הראשי לא נמצא בחשבון, עובר לחלופיים...');skipToFb=true;break}
if(!isBusy(e))throw e;
if(i<2){add('n','המודל עמוס, מנסה שוב...');await sleep(4000*(i+1))}
}
}
if(!skipToFb)add('n','המודל הראשי עדיין עמוס, עובר למודלי פלאש חלופיים...');
let fbs=cfg.fb.split(',').map(s=>s.trim()).filter(Boolean);
if(!fbs.length)fbs=await autoFb();
for(const f of fbs.slice(0,3)){
try{return{...await call(f,contents),model:f}}
catch(e){if(isBusy(e)||e.status==404){add('n',`${f} לא זמין כרגע, ממשיך הלאה...`);continue}throw e}
}
throw{all:true};
}
async function send(text){
text=(text||$('#q').value).trim();if(!text||busy)return;
if(!cfg.key){$('#dlg').showModal();return}
busy=true;$('#send').disabled=true;$('#q').value='';
add('u g',text);
const w=add('ai','');w.insertAdjacentHTML('beforeend','<span class="dots"><span>●</span><span>●</span><span>●</span></span> '+T('בונה...'));
const ctx=Object.keys(files).length?'\n\nCURRENT FILES:\n'+Object.entries(files).map(([n,c])=>`<<<FILE:${n}>>>\n${c}<<<END>>>`).join('\n'):'';
const contents=[...hist.map(h=>({role:h.role,parts:[{text:h.text}]})),{role:'user',parts:[{text:text+($('#st').value?'\n\nDesign style: '+$('#st').value:'')+ctx}]}];
try{
const {text:out,model,fr}=await gen(contents);
const nf=parse(out),plan=out.split('<<<FILE:')[0].trim();
w.remove();
add('ai g',(plan||T('הנה התוצאה.'))+(Object.keys(nf).length?'':T('\n(לא הוחזרו קבצים)')),'נענה ע"י '+model);
if(Object.keys(nf).length){vers.push(JSON.stringify(files));files={...files,...nf};cur=Object.keys(nf)[0];if(nf['index.html'])page='index.html';refresh()}
if(fr==='MAX_TOKENS')add('n','התשובה נקטעה בגלל מגבלת האורך של המודל. בקשו "המשך" או אתר קטן יותר.');
hist.push({role:'user',text},{role:'model',text:plan||'ok'});hist=hist.slice(-12);
}catch(e){
w.remove();
if(e.all)add('er','כל המודלים עמוסים כרגע. נסו שוב בעוד דקה.');
else if(e.net)add('er','לא הצלחתי להתחבר ל-Google. פתחו את הקובץ ישירות בדפדפן או ב-GitHub Pages (לא בתוך תצוגה מקדימה), ובדקו שחוסם פרסומות או סינון אינטרנט לא חוסמים את generativelanguage.googleapis.com. אפשר ללחוץ בהגדרות על "בדיקת חיבור".');
else add('er','שגיאה'+(e.status?` (${e.status})`:'')+': '+(e.msg||e.message||'לא ידועה')+(e.status==400||e.status==403?'\nבדקו את מפתח ה-API בהגדרות.':''));
}
busy=false;$('#send').disabled=false;
}
/* UI */
$('#send').onclick=()=>send();
$('#q').onkeydown=e=>{if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();send()}};
['אתר לעסק קפה עם 4 עמודים','דף נחיתה לאפליקציית כושר','תיק עבודות למעצבת גרפית','חנות אונליין לצמחים'].forEach(t=>{const b=document.createElement('button');b.className='chip';b.textContent=t;b.onclick=()=>send(b.textContent);$('#chips').append(b)});
$('#t1').onclick=()=>{$('#t1').className='on';$('#t2').className='';$('#stage').style.display='flex';$('#code').style.display='none'};
$('#t2').onclick=()=>{$('#t2').className='on';$('#t1').className='';$('#stage').style.display='none';$('#code').style.display='flex';refresh()};
$('#pg').onchange=e=>{page=e.target.value;refresh(true)};
$('#dv').onchange=e=>$('#fr').style.width=e.target.value;
let tm;$('#ed').oninput=e=>{files[cur]=e.target.value;clearTimeout(tm);tm=setTimeout(()=>{save();if($('#fr').srcdoc!==undefined&&page)$('#fr').srcdoc=build(page)},500)};
window.addEventListener('message',e=>{const p=e.data&&e.data.nav;if(!p)return;const f=[p,p+'.html'].find(x=>files[x]);if(f){page=f;refresh(true)}});
$('#undo').onclick=()=>{if(vers.length){files=JSON.parse(vers.pop());refresh()}};
$('#reset').onclick=()=>{if(confirm(T('להתחיל מחדש?'))){files={};hist=[];vers=[];$('#msgs').innerHTML='';refresh()}};
$('#cp').onclick=async()=>{await navigator.clipboard.writeText(files[cur]||'');$('#cp').textContent=T('הועתק ✓');setTimeout(()=>$('#cp').textContent=T('העתק'),1200)};
$('#nt').onclick=()=>{if(page)window.open(URL.createObjectURL(new Blob([build(page).replace(NAV,'')],{type:'text/html'})))};
$('#zip').onclick=async()=>{if(!Object.keys(files).length)return;const z=new JSZip();for(const n in files)z.file(n,files[n]);const a=document.createElement('a');a.href=URL.createObjectURL(await z.generateAsync({type:'blob'}));a.download='website.zip';a.click()};
$('#cfgb').onclick=()=>{$('#k').value=cfg.key;$('#mdl').value=cfg.model;$('#fb').value=cfg.fb;$('#dlg').showModal()};
$('#tst').onclick=async()=>{
const r={set textContent(v){$('#tr').textContent=T(v)}};r.textContent='בודק...';
const k=$('#k').value.trim(),m=$('#mdl').value.trim()||'gemini-3.8-flash';
try{
const x=await gf('https://generativelanguage.googleapis.com/v1beta/models?pageSize=200',{headers:{'x-goog-api-key':k}});
const j=await x.json();
if(!x.ok){r.textContent='שגיאה '+x.status+': '+((j.error&&j.error.message)||'');return}
const ns=(j.models||[]).map(o=>o.name.replace('models/',''));
r.textContent=ns.includes(m)?'החיבור תקין והמודל קיים ✓':'החיבור תקין, אבל המודל "'+m+'" לא קיים. זמינים למשל: '+ns.filter(n=>/flash/.test(n)).slice(0,4).join(', ');
}catch(e){r.textContent=e.net?'אין חיבור ל-Google (חסימה, תצוגה מקדימה או אינטרנט)':String(e.msg||e)}
};
$('#cl').onclick=()=>$('#dlg').close();
$('#sv').onclick=()=>{cfg={key:$('#k').value.trim(),model:$('#mdl').value.trim()||'gemini-3.8-flash',fb:$('#fb').value.trim()};try{localStorage.setItem('cfg',JSON.stringify(cfg))}catch(e){}$('#dlg').close()};
/* MBbot code: i18n, themes, avatars, extras */
let LG='he';try{LG=localStorage.getItem('lg')||'he'}catch(e){}
const D={
[`חדש`]:`New`,[`⚙ הגדרות`]:`⚙ Settings`,[`גרסה קודמת`]:`Previous version`,[`שלח`]:`Send`,[`תצוגה`]:`Preview`,[`קוד`]:`Code`,[`עמוד`]:`Page`,[`מחשב`]:`Desktop`,[`טאבלט`]:`Tablet`,[`נייד`]:`Mobile`,[`העתק`]:`Copy`,[`הועתק ✓`]:`Copied ✓`,[`חלון חדש`]:`New window`,[`הורד ZIP`]:`Download ZIP`,[`הקנבס ריק`]:`The canvas is empty`,[`הגדרות`]:`Settings`,[`סגור`]:`Close`,[`שמור`]:`Save`,[`מסך מלא`]:`Fullscreen`,[`הקלטה קולית`]:`Voice input`,
[`תארו את האתר שתרצו, או מה לשנות בו...`]:`Describe the website you want, or what to change...`,
[`כתבו בצ'אט איזה אתר לבנות, והוא יופיע כאן עם תצוגה מקדימה חיה.`]:`Tell the chat what to build and it appears here with a live preview.`,
[`עוזר קוד שבונה אתרים בשניות`]:`Builds websites in seconds`,
[`תמונות פרופיל של MBbot code`]:`MBbot code profile pictures`,[`תמונות פרופיל`]:`Profile pictures`,
[`מפתח API של Google AI Studio`]:`Google AI Studio API key`,[`מודל ראשי`]:`Primary model`,
[`מודלים חלופיים (עד 3, מופרדים בפסיק). ריק = זיהוי אוטומטי מהחשבון`]:`Fallback models (up to 3, comma-separated). Empty = auto-detect`,
[`בדיקת חיבור`]:`Test connection`,[`המפתח נשמר בדפדפן שלכם בלבד ונשלח רק ל-Google.`]:`Your key stays in your browser and is sent only to Google.`,
[`סגנון: חופשי`]:`Style: Auto`,[`מינימליסטי`]:`Minimal`,[`זכוכית`]:`Glass`,[`ניאו-ברוטליסט`]:`Neo-brutalist`,[`יוקרתי כהה`]:`Dark luxury`,[`משחקי`]:`Playful`,
[`אתר לעסק קפה עם 4 עמודים`]:`Coffee shop site with 4 pages`,[`דף נחיתה לאפליקציית כושר`]:`Landing page for a fitness app`,[`תיק עבודות למעצבת גרפית`]:`Portfolio for a graphic designer`,[`חנות אונליין לצמחים`]:`Online plant store`,
[`היי, אני MBbot code. תארו לי אתר ואבנה אותו עם כמה עמודים, עיצוב מלוטש ותצוגה חיה. אפשר גם לבחור סגנון, ערכת נושא ושפה בראש העמוד, ואחר כך לבקש שינויים בצ'אט או לערוך את הקוד ישירות.`]:`Hi, I'm MBbot code. Describe a website and I'll build it with multiple pages, polished design and a live preview. You can pick a style, theme and language at the top, then ask for changes in chat or edit the code directly.`,
[`בודק...`]:`Checking...`,[`בונה...`]:`Building...`,[`הנה התוצאה.`]:`Here is the result.`,[`(לא הוחזרו קבצים)`]:`(no files returned)`,
[`המודל עמוס, מנסה שוב...`]:`The model is busy, retrying...`,
[`המודל הראשי עדיין עמוס, עובר למודלי פלאש חלופיים...`]:`Primary model still busy, switching to fallback Flash models...`,
[`המודל הראשי לא נמצא בחשבון, עובר לחלופיים...`]:`Primary model not found, switching to fallbacks...`,
[`לא זמין כרגע, ממשיך הלאה...`]:`unavailable, moving on...`,
[`כל המודלים עמוסים כרגע. נסו שוב בעוד דקה.`]:`All models are busy. Please try again in a minute.`,
[`שגיאה`]:`Error`,[`נענה ע"י`]:`Answered by`,[`בדקו את מפתח ה-API בהגדרות.`]:`Check your API key in Settings.`,[`התקבלה תשובה ריקה`]:`Empty response received`,
[`התשובה נקטעה בגלל מגבלת האורך של המודל. בקשו "המשך" או אתר קטן יותר.`]:`The reply was cut off by the model length limit. Ask to "continue" or for a smaller site.`,
[`להתחיל מחדש?`]:`Start over?`,[`הדפדפן לא תומך בהקלטה קולית.`]:`Voice input is not supported in this browser.`,
[`לא הצלחתי להתחבר ל-Google. פתחו את הקובץ ישירות בדפדפן או ב-GitHub Pages (לא בתוך תצוגה מקדימה), ובדקו שחוסם פרסומות או סינון אינטרנט לא חוסמים את generativelanguage.googleapis.com. אפשר ללחוץ בהגדרות על "בדיקת חיבור".`]:`Could not reach Google. Open the file directly in a browser or on GitHub Pages (not inside a preview), and make sure an ad blocker or web filter is not blocking generativelanguage.googleapis.com. You can use "Test connection" in Settings.`,
[`החיבור תקין והמודל קיים ✓`]:`Connection OK and the model exists ✓`,[`החיבור תקין, אבל המודל`]:`Connection OK, but the model`,[`לא קיים. זמינים למשל:`]:`does not exist. Available e.g.:`,[`אין חיבור ל-Google (חסימה, תצוגה מקדימה או אינטרנט)`]:`Cannot reach Google (blocked, preview or network)`};
const PR=Object.entries(D).sort((a,b)=>b[0].length-a[0].length),PE=PR.map(([a,b])=>[b,a]).sort((p,q)=>q[0].length-p[0].length),R=Object.fromEntries(PE);
const FR=['שגיאה','נענה ע"י','Error','Answered by'];
function tr(s,to){const m=to=='en'?D:R,k=s.trim();if(m[k])return s.replace(k,()=>m[k]);let o=s;for(const [a,b] of to=='en'?PR:PE)if(a.length>=9||FR.includes(a))o=o.split(a).join(b);return o}
const T=s=>LG=='en'?tr(s,'en'):s;
function applyLang(){
document.documentElement.lang=LG;document.documentElement.dir=LG=='en'?'ltr':'rtl';
const w=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT),L=[];let n;while(n=w.nextNode())L.push(n);
L.forEach(n=>{const p=n.parentElement;if(!p||/^(SCRIPT|STYLE|TEXTAREA)$/.test(p.tagName)||p.classList.contains('g')||!n.nodeValue.trim())return;const v=tr(n.nodeValue,LG);if(v!==n.nodeValue)n.nodeValue=v});
document.querySelectorAll('[placeholder],[title]').forEach(e=>['placeholder','title'].forEach(a=>{if(e.hasAttribute(a))e.setAttribute(a,tr(e.getAttribute(a),LG))}));
$('#lg').textContent=LG=='en'?'עב':'EN';
}
$('#lg').onclick=()=>{LG=LG=='en'?'he':'en';try{localStorage.setItem('lg',LG)}catch(e){}applyLang()};
/* bot avatars (MB) */
const VS=[['#7c6cff','#38d6c4','#fff',18],['#0b0d14','#1a1f33','#38d6c4',32,'#7c6cff'],['#ff6b6b','#ffb454','#fff',32],['#ffffff','#e4e8ff','#4a3fd6',18,'#c9cffd']];
function vsvg(i,id){const [a,b,c,r,st]=VS[i];return '<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 64 64"><defs><linearGradient id="'+id+'" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="'+a+'"/><stop offset="1" stop-color="'+b+'"/></linearGradient></defs><rect x="1.5" y="1.5" width="61" height="61" rx="'+r+'" fill="url(#'+id+')"'+(st?' stroke="'+st+'" stroke-width="3"':'')+'/><text x="32" y="43" text-anchor="middle" font-family="Arial,Helvetica,sans-serif" font-weight="800" font-size="30" fill="'+c+'" letter-spacing="-1">mb</text></svg>'}
const sm=(i,id,n)=>vsvg(i,id).replace('width="512" height="512"','width="'+n+'" height="'+n+'"'),AVS=()=>sm(0,'ga',22);
function dl(i,png){const s=vsvg(i,'d'),a=document.createElement('a'),nm='MBbot-code-'+(i+1);
if(!png){a.href=URL.createObjectURL(new Blob([s],{type:'image/svg+xml'}));a.download=nm+'.svg';a.click();return}
const im=new Image();im.onload=()=>{const c=document.createElement('canvas');c.width=c.height=512;c.getContext('2d').drawImage(im,0,0,512,512);c.toBlob(b=>{a.href=URL.createObjectURL(b);a.download=nm+'.png';a.click()})};
im.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(s)}
$('#logo').innerHTML=sm(0,'lgo',36);
$('#avg').innerHTML=VS.map((_,i)=>'<div style="text-align:center">'+sm(i,'q'+i,120)+'<div style="margin-top:8px"><button class="btn" onclick="dl('+i+',1)">PNG</button> <button class="btn" onclick="dl('+i+')">SVG</button></div></div>').join('');
$('#logo').onclick=()=>$('#av').showModal();$('#avc').onclick=()=>$('#av').close();
document.head.insertAdjacentHTML('beforeend','<link rel="icon" href="data:image/svg+xml,'+encodeURIComponent(vsvg(0,'f'))+'">');
/* themes */
const TH={aurora:'#7c6cff',ocean:'#18a0fb',sunset:'#ff6b6b',light:'#e8ebf8'};
function setTh(t){document.documentElement.dataset.th=t;try{localStorage.setItem('th',t)}catch(e){}document.querySelectorAll('.sw').forEach(b=>b.classList.toggle('on',b.dataset.t==t))}
for(const t in TH){const b=document.createElement('button');b.className='sw';b.dataset.t=t;b.title=t;b.style.background=TH[t];b.onclick=()=>setTh(t);$('#sws').append(b)}
let th0='aurora';try{th0=localStorage.getItem('th')||'aurora'}catch(e){}setTh(th0);
/* extras: voice, fullscreen, autosave */
$('#mic').onclick=()=>{const SR=window.SpeechRecognition||window.webkitSpeechRecognition;if(!SR)return add('n','הדפדפן לא תומך בהקלטה קולית.');const r=new SR();r.lang=LG=='en'?'en-US':'he-IL';r.onresult=e=>{$('#q').value+=e.results[0][0].transcript};r.start()};
$('#fs').onclick=()=>{const f=$('#fr');f.requestFullscreen&&f.requestFullscreen()};
const save=()=>{try{localStorage.setItem('proj',JSON.stringify({files,hist}))}catch(e){}};
try{const P=JSON.parse(localStorage.getItem('proj')||'null');if(P){files=P.files||{};hist=P.hist||[]}}catch(e){}
add('ai',`היי, אני MBbot code. תארו לי אתר ואבנה אותו עם כמה עמודים, עיצוב מלוטש ותצוגה חיה. אפשר גם לבחור סגנון, ערכת נושא ושפה בראש העמוד, ואחר כך לבקש שינויים בצ'אט או לערוך את הקוד ישירות.`);
refresh();applyLang();
if(!cfg.key)setTimeout(()=>$('#dlg').showModal(),400);
</script>
</body>
</html>