class toastMessage { constructor(title, message, time, background) { this.title = title; this.message = message; this.time = time; this.background = background; } getElement() { return $(``); } getInstance() { return bootstrap.Toast.getOrCreateInstance(this.getElement()); } } function randomBgColor() { var index = Math.floor(Math.random() * 6); var colors = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']; return colors[index]; } function convertByteSize(value, decimalPlaces = 2) { if (decimalPlaces < 0) { throw new Error("decimalPlaces must be non-negative."); } if (value < 0) { return `-${convertByteSize(-value, decimalPlaces)}`; } if (value === 0) { return "0"; } const sizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; const mag = Math.floor(Math.log(value) / Math.log(1024)); const adjustedSize = value / (1 << (mag * 10)); if (Math.round(adjustedSize, decimalPlaces) >= 1000) { mag++; adjustedSize /= 1024; } return `${adjustedSize.toFixed(decimalPlaces)} ${sizeSuffixes[mag]}`; } function getIPInfo(ipAddress) { const url = 'https://ipinfo.techgarage.ir/get_info'; const request = new XMLHttpRequest(); request.open('POST', url, false); let formData = new FormData(); formData.append("ip", ipAddress); formData.append("ipv", "4"); formData.append("source", "ipregistry"); request.send(formData); if (request.status !== 200) { console.error('Failed to fetch data'); return null; } const data = JSON.parse(request.responseText).ipregistry; data.country = data.country ? formatCountryName(data.country) : "N/A"; return data; } function formatCountryName(country) { return country.length <= 4 ? country.toUpperCase() : country; }