Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (95 loc) · 3.59 KB
/
Copy pathindex.js
File metadata and controls
116 lines (95 loc) · 3.59 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const WEATHER_KEY='4ad3b7f831538b29534f532fe9c86f41';
const WEATHER_URL='http://api.openweathermap.org/data/2.5/weather';
const GOOGLEMAP_DIST_CALC_KEY='AIzaSyBH1GluPCAfCFpR_Imp2aru3hoGHWAVQQY';
const GOOGLEMAP_DIST_CALC_URL='https://maps.googleapis.com/maps/api/distancematrix/json';
const CURRENCY_EXCH_URL_AND_KEY='http://www.apilayer.net/api/live?access_key=236f07f596ae922dfae06579eb7c2ee5¤cies=EUR,GBP,JPY&source = USD&format = 1';
const NEWS_KEY_URL='https://newsapi.org/v2/top-headlines?sources=bbc-news&apiKey=407cb170cbf946a4ab4cf0dccbe83f0e';
/* ++++++++++++++++++++++++++++WEATHER++++++++++++++++++++++++++++++++*/
var connection;
var city;
function getWeather(){
connection = new XMLHttpRequest();
city = document.querySelector('#weather input').value;
connection.open("GET", WEATHER_URL+'?'+'appid='+WEATHER_KEY+'&q='+city+'&units=metric');
connection.onload=showWeather;
connection.send();
}
function showWeather(){
var data = JSON.parse(connection.responseText);
var temperature=data.main.temp;
var humidity=data.main.humidity;
var temp_min=data.main.temp_min;
var temp_max=data.main.temp_max;
var location_name=data.name;
document.querySelector('#results').innerHTML=
`<table>
<tr>
<td>Location: ${location_name}</td>
</tr>
<tr>
<td>Temperature: ${temperature}℃</td>
</tr>
<tr>
<td>Humidity: ${humidity}%</td>
</tr>
<tr>
<td>Min temperature: ${temp_min}℃</td>
</tr>
<tr>
<td>Max temperature: ${temp_max}℃</td>
</tr>
</table>`;
}
/*+++++++++++++++++++++++++++++++NEWS++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function getNews(){
connection = new XMLHttpRequest();
connection.open("GET", NEWS_KEY_URL);
connection.onload=showNews;
connection.send();
}
function showNews(){
data = JSON.parse(connection.responseText);
document.querySelector('#newsTable').innerHTML=
"<tr><td><a href=\""+data.articles[0].url+"\""+">"+data.articles[0].title+
"</a></td></tr><tr><td><a href=\""+data.articles[1].url+"\""+">"+data.articles[1].title+
"</a></td></tr><tr><td><a href=\""+data.articles[2].url+"\""+">"+data.articles[2].title+
"</a></td></tr><tr><td><a href=\""+data.articles[3].url+"\""+">"+data.articles[3].title+
"</a></td></tr><tr><td><a href=\""+data.articles[4].url+"\""+">"+data.articles[4].title+
"</a></td></tr>";
}
/*for(var i=0;i<data.articles.length;i++){
document.querySelector('#newsTable').innerHTML=
"<tr><td><a href=\""+data.articles[i].url+"\""+">"+data.articles[i].title+"</a></td></tr>";
}*/
/*+++++++++++++++++++++++++++++++++++++++CURRENCY EXCH+++++++++++++++++++++++++++++++++++++++++++++++*/
function getExchRate(){
connection = new XMLHttpRequest();
connection.open("GET", CURRENCY_EXCH_URL_AND_KEY);
connection.onload=showExchRate;
connection.send();
}
window.onload=getExchRate();
setInterval(getExchRate, 100000);
function showExchRate(){
var data = JSON.parse(connection.responseText);
var EUR=data.quotes["USDEUR"];
var GBP=data.quotes["USDGBP"];
var JPY=data.quotes["USDJPY"];
document.querySelector('#exChCon').innerHTML =
`<table>
<tr>
<td></td>
</tr>
<tr>
<td>EUROS: ${EUR} €</td>
</tr>
<tr>
<td>Great Britain Pound: ${GBP} £</td>
</tr>
<tr>
<td>Japane Yen: ${JPY} ¥</td>
</tr>
<td id="refferenceInfo">*Refference currency is US Dollar</td>
</tr>
</table>`;
}