-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchLiveToolVersions.html
More file actions
72 lines (72 loc) · 2.7 KB
/
fetchLiveToolVersions.html
File metadata and controls
72 lines (72 loc) · 2.7 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
<script>
fetch('https://api.micronutrient.support/v2/self/version').then(function (response) {
// The API call was successful!
return response.json();
}).then(function (data) {
// This is the JSON from our response
Array.from(document.getElementsByClassName("replace")).forEach(
function(element, index, array) {
if(element.innerHTML === 'api-version') {
element.innerHTML = data.data[0].api
}
if(element.innerHTML === 'data-seed') {
element.innerHTML = data.data[0].seed
}
if(element.innerHTML === 'data-schema') {
element.innerHTML = data.data[0].schema
}
console.log(element.innerHTML)
// do stuff
}
);
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
Array.from(document.getElementsByClassName("replace")).forEach(
function(element, index, array) {
if(element.innerHTML === 'api-version') {
element.innerHTML = 'Error loading API version'
element.classList.add('error')
}
if(element.innerHTML === 'data-seed') {
element.innerHTML = 'Error loading data seed version'
element.classList.add('error')
}
if(element.innerHTML === 'data-schema') {
element.innerHTML = 'Error loading data schema version'
element.classList.add('error')
}
}
);
});
fetch('https://maps.micronutrient.support/assets/version.json').then(function (response) {
// The API call was successful!
console.log(response)
return response.json();
}).then(function (data) {
console.log(data)
// This is the JSON from our response
Array.from(document.getElementsByClassName("replace")).forEach(
function(element, index, array) {
if(element.innerHTML === 'tool-version') {
element.innerHTML = data.version
}
}
);
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
Array.from(document.getElementsByClassName("replace")).forEach(
function(element, index, array) {
if(element.innerHTML === 'tool-version') {
element.innerHTML = 'Error loading tool version'
element.classList.add('error')
}
}
);
});
</script>
<style>
.replace { font-weight: bold; }
.error { color: #990000; }
</style>