// استهداف عناصر HTML const promptInput = document.getElementById("prompt"); const generateButton = document.getElementById("generate"); const outputDiv = document.getElementById("output"); // مفتاح API الخاص بـ Gemini (استبدله بمفتاحك) const GEMINI_API_KEY = "AIzaSyBlkMn-zVlQyOERE4cLjnI-d24eMf5slGo"; const GEMINI_API_URL = "https://api.gemini.com/v1/your-endpoint"; // عدّل الرابط إذا كان مختلفًا // عند الضغط على الزر "Generate" generateButton.addEventListener("click", async () => { const prompt = promptInput.value; if (!prompt) { outputDiv.textContent = "Please enter a topic or prompt!"; return; } // تنظيف منطقة الإخراج outputDiv.textContent = "Generating your article..."; try { // إرسال طلب إلى Gemini API const response = await fetch(GEMINI_API_URL, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${GEMINI_API_KEY}`, // مفتاح المصادقة }, body: JSON.stringify({ prompt: prompt, max_tokens: 500, // عدد الكلمات أو الرموز المطلوبة }), }); // التحقق من حالة الاستجابة if (!response.ok) { throw new Error(`Error: ${response.statusText}`); } // معالجة النتيجة const data = await response.json(); const article = data.choices[0].text; // تعديل بناءً على شكل استجابة Gemini // عرض المقالة في منطقة الإخراج outputDiv.textContent = article; } catch (error) { // معالجة الأخطاء outputDiv.textContent = `An error occurred: ${error.message}`; } });