أداة الكود — تحرير / تشغيل / حفظ
مكان إعلان — 728×90
البيئة جاهزة
أحرف: 0
أسطر: 1
حجم: 0 B
المخرجات / المعاينة
HTML — iframe sandbox
مكان إعلان — 300×250
مرحبًا ✨
\nهذا مثال HTML داخل المعاينة.
\n \n\n` : '\n\n\n \n \nتم حقن نص بواسطة JS
');` : `/* اكتب JavaScript هنا */`; } else if(lang==='json'){ snip = kind==='demo' ? `{"name":"مثال","version":"1.0.0","items":[1,2,3]}` : `{"key":"value"}`; } else if(lang==='py'){ snip = kind==='demo' ? `import sys\nprint('Hello from Python ' + sys.version)\nfor i in range(3):\n print('سطر', i)` : `# اكتب كود بايثون هنا\nprint('Hello')`; } editor.value = snip; updateStats(); autosave(); } // أحداث editor.addEventListener('input', ()=>{ updateStats(); autosave(); }); fileInput.addEventListener('change', (e)=>{ const f = e.target.files?.[0]; openFile(f); fileInput.value=''; }); runBtn.addEventListener('click', runCode); clearBtn.addEventListener('click', ()=>{ editor.value=''; updateStats(); autosave(); }); saveBtn.addEventListener('click', downloadFile); newBtn.addEventListener('click', ()=>{ editor.value=''; applySnippet('blank'); updateStats(); autosave(); }); // تبويبات القوالب السريعة document.getElementById('starterTab').addEventListener('click', (e)=>{ const btn = e.target.closest('.tab'); if(!btn) return; [...e.currentTarget.children].forEach(b=>b.classList.remove('active')); btn.classList.add('active'); applySnippet(btn.dataset.snippet); }); langSel.addEventListener('change', ()=>{ onLangChange(); autosave(); }); filename.addEventListener('input', autosave); // سحب وإفلات window.addEventListener('dragover', e=>{ e.preventDefault(); }); window.addEventListener('drop', e=>{ e.preventDefault(); const f = e.dataTransfer.files?.[0]; openFile(f); }); // اختصارات لوحة المفاتيح window.addEventListener('keydown', (e)=>{ if(e.ctrlKey && (e.key==='s' || e.key==='S')){ e.preventDefault(); downloadFile(); } if(e.ctrlKey && (e.key==='o' || e.key==='O')){ e.preventDefault(); fileInput.click(); } if(e.ctrlKey && (e.key==='n' || e.key==='N')){ e.preventDefault(); newBtn.click(); } if(e.ctrlKey && e.key==='Enter'){ e.preventDefault(); runBtn.click(); } }); // أدوات الإخراج document.getElementById('copyOutput').addEventListener('click', ()=>{ const txt = outputBox.classList.contains('hidden') ? '' : outputBox.textContent; if(!txt){ return; } const ta = document.createElement('textarea'); ta.value = txt; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); ta.remove(); }); document.getElementById('openNewTab').addEventListener('click', ()=>{ const lang = langSel.value; const code = editor.value || ''; if(lang==='html'){ const url = URL.createObjectURL(new Blob([code], {type:'text/html'})); window.open(url, '_blank'); setTimeout(()=> URL.revokeObjectURL(url), 2000); } else if(lang==='css'){ const url = URL.createObjectURL(new Blob([buildHTMLfromCSS(code)], {type:'text/html'})); window.open(url, '_blank'); setTimeout(()=> URL.revokeObjectURL(url), 2000); } else if(lang==='js'){ const url = URL.createObjectURL(new Blob([buildHTMLfromJS(code)], {type:'text/html'})); window.open(url, '_blank'); setTimeout(()=> URL.revokeObjectURL(url), 2000); } else if(lang==='json'){ const txt = (()=>{ try{ return JSON.stringify(JSON.parse(code), null, 2); }catch(e){ return '❌ JSON غير صالح\n'+e.toString(); } })(); const url = URL.createObjectURL(new Blob([`${txt.replace(/`], {type:'text/html'})); window.open(url, '_blank'); setTimeout(()=> URL.revokeObjectURL(url), 2000);
} else if(lang==='py'){
alert('لفتح بايثون في تبويب مستقل، انسخ الكود يدويًا حاليًا. (يمكن لاحقًا إنشاء صفحة خاصة لبايثون)');
}
});
// تهيئة
function boot(){ onLangChange(); restore(); updateStats(); ensureFilenameExt(); editor.spellcheck=false; editor.wrap='off'; editor.placeholder = 'اكتب الكود هنا…'; }
document.addEventListener('DOMContentLoaded', boot);
// ملاحظات أمان: تشغيل JavaScript يتم داخل iframe مع sandbox=allow-scripts لمنع الوصول إلى الصفحة الأصلية.