-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
22 lines (21 loc) · 985 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
document
.getElementsByName("source")
.forEach(function(element) {
var ipAddress = element.value.substring(0, element.value.indexOf('/'));
var url = "https://freegeoip.net/json/" + ipAddress;
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var location = JSON.parse(xmlHttp.responseText)
var cn = location.country_code + ", " + location.region_name;
console.log(ipAddress + " - " + cn);
var span = document.createElement("span");
span.style.position = "absolute";
span.style.right = "0px";
span.innerText = cn;
element.parentElement.appendChild(span);
}
}
xmlHttp.open( "GET", url, true ); // false for synchronous request
xmlHttp.send( null );
}, this);