-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 lines (43 loc) · 1.54 KB
/
main.js
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
let json_data = '';
function getValue() {
const inputValue = document.getElementById("imgURL").value;
return inputValue;
}
function displayImage() {
const inputValue = getValue();
const img = document.getElementById("img-to-txt");
img.src = inputValue;
}
function sendURL(data) {
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://europe-west3-summer-hackday.cloudfunctions.net/altitude?url=" + data);
let container = document.querySelector("figcaption");
container.innerHTML = "LOADING...";
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onload = () => {
json_data = JSON.parse(xhr.responseText);
// json_data = {
// "French": "Une femme chantant dans un microphone",
// "German": "Eine Frau singt in ein Mikrofon",
// "English": "A woman singing into a microphone",
// "Spanish": "Una mujer cantando en un micrófono",
// "Polish": "Kobieta śpiewająca do mikrofonu",
// "Italian": "Una donna che canta in un microfono"
// };
container.innerHTML = container.innerHTML.replace('LOADING...', '');
Object.keys(json_data).forEach(function(k){
let p = document.createElement("p");
p.innerText = k + ' - ' + json_data[k];
container.appendChild(p);
});
}
xhr.send();
}
function getDesc() {
const url = getValue();
return sendURL(url)
}
function displayDesc() {
displayImage();
getDesc();
}