dip/static/js/main.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-06-05 11:14:02 +02:00
const dip_ip = document.getElementById("dip_ip");
const dip_hostname = document.getElementById("dip_hostname");
const dip_city = document.getElementById("dip_city");
const dip_country = document.getElementById("dip_country");
const dip_as_number = document.getElementById("dip_as_number");
const dip_as_org = document.getElementById("dip_as_org");
function setData(res) {
dip_ip.innerHTML = res["ip"];
dip_hostname.innerHTML = res["hostname"];
dip_city.innerHTML = res["city"];
dip_country.innerHTML = res["country"];
dip_as_number.innerHTML = res["as"]["number"];
dip_as_org.innerHTML = res["as"]["org"];
}
2024-06-10 01:14:01 +02:00
function updateIP() {
2023-07-17 21:12:44 +02:00
let ip = "";
2023-07-17 21:12:44 +02:00
if (window.location.pathname.length > 4) {
ip = window.location.pathname.split("/")[1];
}
2024-06-05 11:14:02 +02:00
const localdata = localStorage.getItem("data");
if (localdata) {
const data = JSON.parse(localdata);
setData(data);
}
2023-07-13 22:25:21 +02:00
fetch(`/json/${ip}`).then((response) => {
2024-06-05 11:14:02 +02:00
response.json().then((data) => {
setData(data);
localStorage.setItem("data",JSON.stringify(data));
2023-07-13 22:25:21 +02:00
});
});
}
2024-06-11 18:43:21 +02:00
updateIP()
2024-06-10 01:14:01 +02:00
setInterval(updateIP,1000);