From 2cc7e443fce2a7a3a2f2a8fd2a64815750ab04be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20K=C3=BCthe?= Date: Sat, 23 Sep 2023 17:09:59 +0200 Subject: [PATCH] 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). --- wwwroot/assets/js/myip.js | 45 +++++++++++++++++++++++++++++++++++++ wwwroot/index.html | 47 +-------------------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 wwwroot/assets/js/myip.js diff --git a/wwwroot/assets/js/myip.js b/wwwroot/assets/js/myip.js new file mode 100644 index 0000000..3b75ec6 --- /dev/null +++ b/wwwroot/assets/js/myip.js @@ -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(); +} diff --git a/wwwroot/index.html b/wwwroot/index.html index 48c4ba0..5387ec6 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -16,53 +16,8 @@ - +