Repository navigation
Expand file tree
/
Copy pathipgeo2.js
More file actions
81 lines (69 loc) · 2.45 KB
/
Copy pathipgeo2.js
File metadata and controls
81 lines (69 loc) · 2.45 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var ipdetails;
var api = 'https://ipapi.co/json/';
var url = api;
function setup() {
removeDummy();
loadJSON(url, gotData);
var button = select('#submit');
button.mousePressed(refresh);
}
function refresh() {
setTimeout(ipAsk,500);
setTimeout(ipv4,500);
}
function ipAsk() {
loadJSON(url, gotData);
}
function gotData(data) {
ipdetails = data;
if (ipdetails) {
document.getElementById("auts").innerHTML = ipdetails.asn;
document.getElementById("city").innerHTML = ipdetails.city;
document.getElementById("coun").innerHTML = ipdetails.country_name + ' (' + ipdetails.country + ')';
document.getElementById("ccc").innerHTML = ipdetails.country_calling_code;
document.getElementById("curr").innerHTML = ipdetails.currency;
document.getElementById("latlon").innerHTML = ipdetails.latitude + ', ' + ipdetails.longitude;
document.getElementById("orga").innerHTML = ipdetails.org;
document.getElementById("ipad").innerHTML = ipdetails.ip;
document.getElementById("region").innerHTML = ipdetails.region + ' (' + ipdetails.region_code + ')';
document.getElementById("timezone").innerHTML = ipdetails.timezone + ' (' + ipdetails.utc_offset + ')';
document.getElementById("zipcode").innerHTML = ipdetails.postal;
}
}
function removeDummy() {
document.getElementById('defaultCanvas0').parentNode.removeChild(document.getElementById('defaultCanvas0'));
}
function tableToCSV(table, filename) {
var data = [];
var rows = document.querySelectorAll(`${table} tr`);
for (var i = 0; i < rows.length; i++) {
var row = [],
cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
row.push(cols[j].innerText);
}
data.push(row.join(","));
}
downloadCSV(data.join("\n"), filename);
}
function downloadCSV(csv, filename) {
var csv_file, download_link;
csv_file = new Blob([csv], { type: "text/csv" });
download_link = document.createElement("a");
download_link.download = filename;
download_link.href = window.URL.createObjectURL(csv_file);
download_link.style.display = "none";
document.body.appendChild(download_link);
download_link.click();
}
function capitalizeAll(str) {
try {
let words = str.split(" ");
for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1);
}
return String(words).replace(/[,]/g, " ");
} catch (err) {
console.log(err);
}
}