Advertisement
zeeph

Untitled

Apr 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. `` window.onload = function () {
  2. let apikey = 'e765f704ed22149780f8d19758009a2ad5fcb0ce579bff00df75bcd2';
  3. let ip = document.querySelector('#ip')
  4. let paysName = document.querySelector('#paysName');
  5. let flagCountry = document.querySelector('#flagCountry');
  6. let fai = document.querySelector('#fai');
  7.  
  8. function searchMyip(myIP) {
  9. fetch(`https://api.ipdata.co/?api-key=${apikey}`).then(result => {
  10. return result.json();
  11. }).then(result => {
  12. init(result);
  13. });
  14. }
  15.  
  16. function init(resultServer) {
  17. console.log(resultServer);
  18. ip.textContent = resultServer.ip;
  19. paysName.textContent = resultServer.country_name + " " + resultServer.country_code;
  20. fai.textContent = resultServer.organisation;
  21. flagCountry.src = resultServer.flag;
  22. latitude = resultServer.latitude;
  23. longitude = resultServer.longitude;
  24.  
  25. var map = L.map('map').setView([latitude, longitude], 13);
  26.  
  27. L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  28. attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  29. }).addTo(map);
  30.  
  31. L.marker([latitude, longitude]).addTo(map)
  32. .bindPopup('You have been cucked.<br> faut payer maintenant.')
  33. .openPopup();
  34. };
  35.  
  36. document.getElementById('recherchebtn').addEventListener('click', () => {
  37. let searchText = document.getElementById('rechercheform').value;
  38. document.getElementById('rechercheDisplay').className = 'my-3 p-3 bg-white rounded shadow-sm';
  39. document.getElementById('mapReveal').className = 'card text-center shadow bg-white rounded mt-4';
  40. if (searchText)
  41. searchWeather(searchText);
  42.  
  43. });
  44. document.getElementById('monIp').addEventListener('click', () => {
  45. let myIP = document.getElementById('rechercheform');
  46. document.getElementById('rechercheDisplay').className = 'my-3 p-3 bg-white rounded shadow-sm';
  47. document.getElementById('mapReveal').className = 'card text-center shadow bg-white rounded mt-4';
  48. if (myIP)
  49. searchMyip(myIP);
  50. });
  51. }``
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement