// Function to detect device type function getDeviceType() { const ua = navigator.userAgent; if (/mobile/i.test(ua)) { return "Mobile Device"; } else { return "PC"; } } // Function to detect device brand (for mobile devices) function getDeviceBrand() { const ua = navigator.userAgent; const match = ua.match(/\b(Android|iPad|iPhone|Windows Phone|IEMobile)\b/i); return match ? match[0] : "Unknown Brand"; } // Function to detect browser type and version function getBrowserInfo() { const ua = navigator.userAgent; let browserName = "Unknown Browser"; let fullVersion = "Unknown Version"; if (/chrome|crios|crmo/i.test(ua)) { browserName = "Google Chrome"; fullVersion = ua.match(/Chrome\/(\d+\.\d+)/i)[1]; } else if (/firefox|fxios/i.test(ua)) { browserName = "Mozilla Firefox"; fullVersion = ua.match(/Firefox\/(\d+\.\d+)/i)[1]; } else if (/safari/i.test(ua) && !/chrome|crios|crmo/i.test(ua)) { browserName = "Apple Safari"; fullVersion = ua.match(/Version\/(\d+\.\d+)/i)[1]; } else if (/msie|trident/i.test(ua)) { browserName = "Microsoft Internet Explorer"; fullVersion = ua.match(/(MSIE |rv:)(\d+\.\d+)/i)[2]; } else if (/edg/i.test(ua)) { browserName = "Microsoft Edge"; fullVersion = ua.match(/Edg\/(\d+\.\d+)/i)[1]; } return `${browserName} (version ${fullVersion})`; } // Function to fetch and display IP address, city, and country async function fetchLocationInfo() { try { const response = await fetch('https://ipapi.co/json/'); const data = await response.json(); const { ip, city, country_name } = data; document.getElementById('ip-info').innerText = `Your IP Address: ${ip}`; document.getElementById('location-info').innerText = `Location: ${city}, ${country_name}`; } catch (error) { console.error('Failed to fetch location information', error); document.getElementById('ip-info').innerText = `Could not fetch IP address.`; document.getElementById('location-info').innerText = `Location: Unknown`; } } // Function to get current time function getCurrentTime() { const now = new Date(); return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' }); } // Function to update time every second function updateTime() { document.getElementById('time-info').innerText = `Current Time: ${getCurrentTime()}`; } // Display device type and brand const deviceType = getDeviceType(); document.getElementById('device-info').innerText = `Device Type: ${deviceType}`; if (deviceType === "Mobile Device") { document.getElementById('brand-info').innerText = `Device Brand: ${getDeviceBrand()}`; } else { document.getElementById('brand-info').style.display = "none"; // Hide brand info for non-mobile devices } // Display browser info document.getElementById('browser-info').innerText = `Browser: ${getBrowserInfo()}`; // Fetch and display IP address, city, and country fetchLocationInfo(); // Display current time initially updateTime(); // Update time every second setInterval(updateTime, 1000);