forked from sanscript-tech/hacking-tools-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (35 loc) · 1.36 KB
/
Copy pathapp.js
File metadata and controls
47 lines (35 loc) · 1.36 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
var temp = {
key: "87cde31000e5170290cebdd94820d23d",
base: "https://api.openweathermap.org/data/2.5/"
}
var notificationElement = document.querySelector(".notification");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setPosition);
notificationElement.innerHTML = "";
}
else {
notificationElement.innerHTML = "Geolocation is not supported by this browser.";
}
function setPosition(position){
let latitude = position.coords.latitude;
let longitude = position.coords.longitude;
getWeather(latitude, longitude);
}
function getWeather(lat,lon) {
fetch(`${temp.base}weather?lat=${lat}&lon=${lon}&units=metric&appid=${temp.key}`)
.then(weather => {
return weather.json();
}).then(displayResults);
}
function displayResults (weather) {
let city = document.querySelector('.location .city');
city.innerText = `${weather.name}, ${weather.sys.country}`;
let temp = document.querySelector('.current .temp');
temp.innerHTML =`${Math.round(weather.main.temp)}<span>°C</span>`
let weather_el = document.querySelector('.current .weather');
weather_el.innerText = weather.weather[0].main;
let wind=document.querySelector('.wind-speed');
wind.innerText=weather.wind.speed;
let deg=document.querySelector('.wind-degree');
deg.innerText=weather.wind.deg;
}