-
Notifications
You must be signed in to change notification settings - Fork 1
/
output.js
74 lines (58 loc) · 2.41 KB
/
output.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const jsonURL = 'https://olddigibox.github.io/sky-box-lookup/database.json'
function getversion() {
//container for info
let infocontainer = document.getElementById('infocontainer')
//get value from um input
let textinput = document.getElementById('textinput').value
//make var name which is a div element
let name = document.createElement('div')
let link = document.createElement('a')
let confirmation = document.createElement('div')
fetch(jsonURL, { method: "Get" })
.then(res => res.json())
.then((json) => {
removeDivs()
//get name of Version Number and set as text
name.innerText = `Name: ${json["a" + textinput].name}`
//get link of Version Number and set as herf
if (json["a" + textinput].link !== 'N/A') {
link.href = `${json["a" + textinput].link}`
}
//set target as _blank
link.target = "_blank";
//get link of Version Number and set text
link.innerText = `Link: ${json["a" + textinput].link}`
//get confirmation of Version Number and set as text
confirmation.innerText = `Confirmation: ${json["a" + textinput].confirmation}`
addClass()
append()
//functions
function removeDivs() {
//elements with class name infotext
var infotext = document.querySelector('.infotext');
//if element in infocontainer with class infotext remove
if (infocontainer.contains(infotext)) {
infocontainer.querySelectorAll('*').forEach(n => n.remove())
}
}
function addClass() {
//add the class infotext to all divs
name.className += "infotext";
if (json["a" + textinput].link !== 'N/A') {
link.className += "infotext helpbutton";
} else {
link.className += "infotext";
}
confirmation.className += "infotext";
}
function append() {
//add them to infocontainer div
infocontainer.append(name)
infocontainer.append(link)
infocontainer.append(confirmation)
}
})
.catch(err => {
console.error(err)
})
}