-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
123 lines (111 loc) · 4.28 KB
/
script.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
const apiUrl = "http://localhost:3000";
// Mendapatkan rekomendasi ban
async function getBanRecommendations() {
const response = await fetch(`${apiUrl}/recommend-ban`);
const data = await response.json();
const banRecommendations = document.getElementById("ban-recommendations");
banRecommendations.innerHTML = data.recommendations
.map((hero) => `<div class="hero-item">${hero}</div>`)
.join("");
}
// Melakukan ban hero
async function banHero(isTeamBan) {
const hero = document.getElementById("ban-hero").value;
const response = await fetch(`${apiUrl}/ban-hero`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ hero, isTeamBan }),
});
const data = await response.json();
document.getElementById("team-bans").innerText = data.teamBans.join(", ");
document.getElementById("enemy-bans").innerText = data.enemyBans.join(", ");
getBanRecommendations();
document.getElementById("ban-hero").value = ""; // Clear input
}
// Mendapatkan rekomendasi pick
async function getPickRecommendations(isTeamPick) {
const response = await fetch(
`${apiUrl}/recommend-pick?isTeamPick=${isTeamPick}`
);
const data = await response.json();
const pickRecommendations = document.getElementById("pick-recommendations");
pickRecommendations.innerHTML = data.recommendations
.map((hero) => `<div class="hero-item">${hero}</div>`)
.join("");
}
// Melakukan pick hero
async function pickHero(isTeamPick) {
const hero = document.getElementById("pick-hero").value;
const response = await fetch(`${apiUrl}/pick-hero`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ hero, isTeamPick }),
});
const data = await response.json();
document.getElementById("team-picks").innerText =
data.currentPicks.team.join(", ");
document.getElementById("enemy-picks").innerText =
data.currentPicks.enemy.join(", ");
// Tampilkan strategi hero
displayHeroStrategy(data.strategy);
getPickRecommendations(isTeamPick); // Refresh rekomendasi pick setelah pick
document.getElementById("pick-hero").value = ""; // Clear input
}
function displayHeroStrategy(strategy) {
const strategyContainer = document.getElementById("hero-strategy-content");
if (strategy) {
strategyContainer.innerHTML = `
<h3>Strategy for ${strategy.hero}</h3>
<p><strong>Strengths:</strong> ${strategy.strengths.join(", ")}</p>
<p><strong>Weaknesses:</strong> ${strategy.weaknesses.join(
", "
)}</p>
${
strategy.tips.length
? `<p><strong>Tips:</strong> ${strategy.tips.join(", ")}</p>`
: ""
}
${
strategy.warnings.length
? `<p><strong>Warnings:</strong> ${strategy.warnings.join(
", "
)}</p>`
: ""
}
`;
} else {
strategyContainer.innerHTML = "<p>No strategy available for this hero.</p>";
}
}
// Mendapatkan counter hero
async function getCounter() {
const hero = document.getElementById("counter-hero").value;
const response = await fetch(`${apiUrl}/counter-hero?hero=${hero}`);
const data = await response.json();
document.getElementById(
"counter-result"
).innerText = `Counters for ${hero}: ${data.counters.join(", ")}`;
document.getElementById("counter-hero").value = ""; // Clear input
}
async function resetDraft() {
const response = await fetch(`${apiUrl}/reset`, {
method: "POST",
});
const data = await response.json();
alert(data.message); // Notifikasi setelah reset berhasil
// Kosongkan tampilan bans dan picks
document.getElementById("team-bans").innerText = "";
document.getElementById("enemy-bans").innerText = "";
document.getElementById("team-picks").innerText = "";
document.getElementById("enemy-picks").innerText = "";
document.getElementById("hero-strategy").innerHTML = "";
document.getElementById("counter-result").innerText = "";
// Muat ulang rekomendasi ban dan pick
getBanRecommendations();
getPickRecommendations(true);
}
// Memuat rekomendasi ban dan pick saat halaman dimuat
document.addEventListener("DOMContentLoaded", () => {
getBanRecommendations();
getPickRecommendations(true); // Rekomendasi pick untuk tim
});