Spaces:
Running
Running
File size: 3,367 Bytes
685e752 |
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 |
document.addEventListener('DOMContentLoaded', function() {
// Fetch IP information on page load
fetchIPInfo();
// Setup refresh button
const refreshBtn = document.getElementById('refresh-btn');
refreshBtn.addEventListener('click', function() {
const icon = this.querySelector('i');
icon.classList.remove('hidden');
this.disabled = true;
fetchIPInfo().finally(() => {
setTimeout(() => {
icon.classList.add('hidden');
this.disabled = false;
}, 500);
});
});
// Theme toggle functionality (if you want to add a toggle button later)
// const themeToggle = document.getElementById('theme-toggle');
// themeToggle.addEventListener('click', function() {
// document.documentElement.classList.toggle('dark');
// localStorage.setItem('darkMode', document.documentElement.classList.contains('dark'));
// });
});
async function fetchIPInfo() {
try {
// First get the IP address
const ipResponse = await fetch('https://api.ipify.org?format=json');
const ipData = await ipResponse.json();
const ipAddress = ipData.ip;
// Then get detailed information using the IP
const infoResponse = await fetch(`https://ipapi.co/${ipAddress}/json/`);
const infoData = await infoResponse.json();
// Update the UI with the fetched data
document.getElementById('ip-address').textContent = ipAddress;
document.getElementById('location').textContent =
`${infoData.city || 'Unknown'}, ${infoData.region || 'Unknown'}`;
document.getElementById('country').textContent =
`${infoData.country_name || 'Unknown'} (${infoData.country || 'XX'})`;
document.getElementById('isp').textContent = infoData.org || 'Unknown ISP';
document.getElementById('timezone').textContent = infoData.timezone || 'Unknown';
// Determine security status (simplified for demo)
const securityStatus = infoData.proxy === true || infoData.vpn === true ?
'⚠️ VPN/Proxy Detected' : '✅ Normal Connection';
document.getElementById('security').textContent = securityStatus;
// Simulate map loading (in a real app you would use Google Maps or similar)
const mapContainer = document.getElementById('map-container');
mapContainer.innerHTML = `
<div class="absolute inset-0 flex items-center justify-center">
<div class="text-center">
<i data-feather="map-pin" class="text-secondary-500 w-12 h-12 mb-2 mx-auto"></i>
<p class="text-gray-800 dark:text-gray-200 font-medium">${infoData.city || 'Your Location'}</p>
</div>
</div>
`;
feather.replace();
} catch (error) {
console.error('Error fetching IP information:', error);
// Show error state in UI
const elements = [
'ip-address', 'location', 'country',
'isp', 'timezone', 'security'
];
elements.forEach(id => {
document.getElementById(id).textContent = 'Failed to load';
document.getElementById(id).classList.add('text-red-500');
});
}
} |