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).
This commit is contained in:
Marek Küthe 2023-09-23 17:09:59 +02:00
parent 9c3338ac95
commit 2cc7e443fc
No known key found for this signature in database
GPG key ID: 7E869146699108C7
2 changed files with 46 additions and 46 deletions

45
wwwroot/assets/js/myip.js Normal file
View file

@ -0,0 +1,45 @@
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();
}

View file

@ -16,53 +16,8 @@
<link rel="stylesheet" href="/assets/css/normalize.css" integrity="sha384-M86HUGbBFILBBZ9ykMAbT3nVb0+2C7yZlF8X2CiKNpDOQjKroMJqIeGZ/Le8N2Qp">
<link rel="stylesheet" href="/assets/css/simple.min.css" integrity="sha384-ZLDMtZ+NjwNE3nk4wWLGpX4atVTD4fql9ruaAw2xFz7CLPlFcwrifgX2HgkdX6X7">
<script>
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();
}
</script>
<script src="/assets/js/myip.js"></script>
</head>
<body>
<header>