ip-checker/assets/static/script.js
2024-08-27 06:01:24 +08:00

54 lines
1.3 KiB
JavaScript

function main() {
fetchAsync("https://api.ip.sb/geoip").then(
function (value) {
v = value;
document.getElementById("check-ipsb-ip").innerHTML = v.ip;
document.getElementById("check-ipsb-location").innerHTML = [
v.city,
v.country,
v.isp,
].join(", ");
},
function (error) {
console.log(error);
},
);
fetchAsync("https://api-v3.speedtest.cn/ip").then(
function (value) {
v = value.data;
document.getElementById("check-speedtestcn-ip").innerHTML = v.ip;
document.getElementById("check-speedtestcn-location").innerHTML = [
v.city,
v.country,
v.isp,
].join(", ");
},
function (error) {
console.log(error);
},
);
fetchAsync("https://api.ipapi.is/").then(
function (value) {
v = value;
document.getElementById("check-ipapiis-ip").innerHTML = v.ip;
document.getElementById("check-ipapiis-location").innerHTML = [
v.location.city,
v.location.country,
v.company.name,
].join(", ");
},
function (error) {
console.log(error);
},
);
}
async function fetchAsync(url) {
let response = await fetch(url);
let data = await response.json();
return data;
}
window.onload = function () {
main();
};