-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
129 lines (90 loc) · 4.18 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
document.getElementById('searchbar').addEventListener('input', function (event) {
sendSearchRequest(this.value);
});
getSearchParams();
function getSearchParams() {
var searchBar = document.getElementById('searchbar');
const searchParams = new URLSearchParams(location.search);
let params = {};
for (let param of searchParams) {
params[param[0]] = param[1];
}
if (params['r'] !== undefined){
searchBar.value = params['r']
sendSearchRequest(params['r']);
}
}
function sendSearchRequest(query) {
// var url = 'http://127.0.0.1/Api-TyroModFusion/result.php?itemResult=' + query;
var url = 'http://vps214.tyrolium.fr/api-fusion/result.php?itemResult=' + query;
fetch(url)
.then(response => response.json())
.then(data => {
// console.log(data);
if (data !== "err"){
addNewMap(data)
}
})
.catch(error => console.error('Error:', error));
}
function addNewMap(data) {
var mapFusion = document.getElementById('fusionResult');
mapFusion.innerHTML = null;
var mapFusionI = document.getElementById('fusionImplication');
mapFusionI.innerHTML = null;
var infoItem = document.getElementById('infoItem');
infoItem.innerHTML = null;
var i = 1;
data.forEach(reponse => {
if (i == 1) {
infoItem.style.background = "#e0e0e0"
infoItem.innerHTML += `
<div id="firstInfoItem">
<img class="itemInfo" src="textures/items/${reponse['name']}.png">
</div>
<div id="secondInfoItem">
<h3>${reponse['name']} <span>#${reponse['tyroid']}</span></h3>
<p>Tier : ${reponse['tier']}</p>
<p>Version : ${reponse['version']}</p>
<p>Nombre de Fusion : ${reponse['fusion_count']}</p>
<p>Combustible : ${reponse['isFuel']}</p>
</div>
`;
} else if (i == 2) {
if (reponse.length !== 0){
mapFusion.innerHTML += `
<h3>Obtention</h3>
`;
reponse.forEach(fusion => {
mapFusion.innerHTML += `
<div class="map">
<h4 class="tierName">Tier ${fusion.tier}</h4>
<img class="item item1" src="textures/items/${fusion.item1}.png" title="${fusion.item1}" onclick="window.location.href = '?r=${fusion.item1}';">
<img class="item item2" src="textures/items/${fusion.item2}.png" title="${fusion.item2}" onclick="window.location.href = '?r=${fusion.item2}';">
<img class="item itemResult" src="textures/items/${fusion.itemResult}.png" title="${fusion.itemResult}" onclick="window.location.href = '?r=${fusion.itemResult}';">
<img class="item itemFuel" src="textures/items/${fusion.itemFuel}.png" title="${fusion.itemFuel}" onclick="window.location.href = '?r=${fusion.itemFuel}';">
</div>
`;
});
}
} else if (i == 3) {
if (reponse.length !== 0){
mapFusionI.innerHTML += `
<h3>Usage</h3>
`;
reponse.forEach(fusion => {
mapFusionI.innerHTML += `
<div class="map">
<h4 class="tierName">Tier ${fusion.tier}</h4>
<img class="item item1" src="textures/items/${fusion.item1}.png" title="${fusion.item1}" onclick="window.location.href = '?r=${fusion.item1}';">
<img class="item item2" src="textures/items/${fusion.item2}.png" title="${fusion.item2}" onclick="window.location.href = '?r=${fusion.item2}';">
<img class="item itemResult" src="textures/items/${fusion.itemResult}.png" title="${fusion.itemResult}" onclick="window.location.href = '?r=${fusion.itemResult}';">
<img class="item itemFuel" src="textures/items/${fusion.itemFuel}.png" title="${fusion.itemFuel}" onclick="window.location.href = '?r=${fusion.itemFuel}';">
</div>
`;
});
}
}
i++;
});
}