-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (35 loc) · 1.02 KB
/
script.js
File metadata and controls
41 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const getApi = async (url) => {
const response = await fetch(url);
const data = await response.json();
return data;
};
async function CheckOnlineStatus(msg) {
let status = document.getElementById("status");
let condition = navigator.onLine ? "ONLINE" : "OFFLINE";
let state = document.getElementById("state");
state.classList.add(condition);
state.innerHTML = condition;
let providerName = document.querySelector(".provider-name");
let providerInfo = document.querySelector(".provider-info");
if (condition === "ONLINE") {
let { org } = await getApi("http://ip-api.com/json/");
console.log(org);
providerName.innerHTML = org;
} else {
providerInfo.style.display = "none";
}
}
function Pageloaded() {
CheckOnlineStatus("load");
window.ononline = function () {
CheckOnlineStatus("online");
location.reload();
};
window.onoffline = function () {
CheckOnlineStatus("offline");
location.reload();
};
}
function getIP(json) {
alert("My public IP address is: " + json.ip);
}