myip.dn42/wwwroot/assets/js/myip.js
Marek Küthe 2cc7e443fc
Outsource JavaScript into seperate file
In general, JS and CSS resources should be in separate files. This improves clarity and security (for example, when using CSP).
2023-09-23 17:12:02 +02:00

45 lines
1.2 KiB
JavaScript

function getdefault() {
fetch('/api')
.then(function (response) {
return response.json();
})
.then(function (data) {
document.getElementById("defaultip").innerHTML=data.ip;
document.getElementById("serverdefault").innerHTML=data.server;
document.getElementById("node_as").innerHTML=data.node_as;
document.getElementById("node_location").innerHTML=data.node_location;
document.getElementById("node_id").innerHTML=data.node_id;
})
}
function getipv4() {
fetch('http://v4.myip.dn42/api')
.then(function (response) {
return response.json();
})
.then(function (data) {
document.getElementById("ipv4").innerHTML=data.ip;
document.getElementById("serveripv4").innerHTML=data.server;
})
}
function getipv6() {
fetch('http://v6.myip.dn42/api')
.then(function (response) {
return response.json();
})
.then(function (data) {
document.getElementById("ipv6").innerHTML=data.ip;
document.getElementById("serveripv6").innerHTML=data.server;
})
}
window.onload = function () {
getdefault();
getipv4();
getipv6();
}