· 5 years ago · Mar 06, 2020, 01:30 PM
1function getGeolocalization(){
2 var i = 0;
3 count = Number(document.getElementById("countData").getAttribute("data-value"))+1;
4 for (i = 0; i < count; i++) {
5 if(document.getElementById("ip_" + i)){
6 ip = document.getElementById("ip_" + i).getAttribute("data-value");
7 setGeo(i, ip);
8 }
9 }
10 }
11
12 function setGeo(id, ip){
13 fetch("getCountry?ip=" + ip).then((resp) => resp.text()).then(function(data) {
14 if(data == "PL"){
15 document.getElementById("geo_" + id).innerHTML = "<img src='https://cdn1.iconfinder.com/data/icons/european-country-flags/84/poland-16.png'>";
16 }else{
17 if(data == "GE"){
18 document.getElementById("geo_" + id).innerHTML = "<img src='https://cdn1.iconfinder.com/data/icons/european-country-flags/83/germany-16.png'>";
19 }else{
20 if(data == "US"){
21 document.getElementById("geo_" + id).innerHTML = "<img src='https://image.flaticon.com/icons/svg/323/323310.svg' width='16px' height='16px'>";
22 }else{
23 if(data == "UK"){
24 document.getElementById("geo_" + id).innerHTML = "<img src='https://image.flaticon.com/icons/svg/323/323329.svg' width='16px' height='16px'>";
25 }else{
26 document.getElementById("geo_" + id).innerHTML = "";
27 }
28 }
29 }
30 }
31 });
32 }
33
34 function setCountryFlag(){
35 var ip = document.getElementById("hiddenIp").getAttribute("data-value");
36 fetch("getCountry?ip=" + ip).then((resp) => resp.text()).then(function(data) {
37 if(data == "PL"){
38 document.getElementById("countryFlag").innerHTML = "<img src='https://cdn1.iconfinder.com/data/icons/european-country-flags/84/poland-16.png'>";
39 }else{
40 if(data == "GE"){
41 document.getElementById("countryFlag").innerHTML = "<img src='https://cdn1.iconfinder.com/data/icons/european-country-flags/83/germany-16.png'>";
42 }else{
43 if(data == "US"){
44 document.getElementById("countryFlag").innerHTML = "<img src='https://image.flaticon.com/icons/svg/323/323310.svg' width='16px' height='16px'>";
45 }else{
46 if(data == "UK"){
47 document.getElementById("countryFlag").innerHTML = "<img src='https://image.flaticon.com/icons/svg/323/323329.svg' width='16px' height='16px'>";
48 }else{
49 document.getElementById("countryFlag").innerHTML = "";
50 }
51 }
52 }
53 }
54 });
55 }
56
57 function sendLike(ip, secretKey){
58 updateLikes("addLike?ip=" + ip + "&secretKey=" + secretKey + "", ip);
59 }
60
61 function updateLikes(a, ip) {
62 fetch(a).then((resp) => resp.text()).then(function(data) {
63 document.getElementById("ip" + ip).innerHTML = data;
64 });
65 }
66
67 window.onscroll = function () {
68 window.scrollTo(0,window.scrollY);
69 };
70
71</script>
72</body>
73</html>