-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictor.js
More file actions
52 lines (47 loc) · 1.74 KB
/
predictor.js
File metadata and controls
52 lines (47 loc) · 1.74 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
function startPrediction() {
let clientSeed = document.getElementById("clientSeed").value.trim();
let serverSeed = document.getElementById("serverSeed").value.trim();
let startButton = document.querySelector(".btn");
let resultDiv = document.getElementById("result");
if (clientSeed === "" || serverSeed === "") {
alert("Both fields must be filled out!");
return;
}
// Show loading state
startButton.textContent = "Loading...";
startButton.disabled = true;
resultDiv.innerHTML = ""; // Clear previous results
// Simulate a 2-second loading effect
setTimeout(() => {
fetch('https://predictor-py.onrender.com', { // NEW: Hosted API
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ clientSeed, serverSeed })
})
.then(response => response.json())
.then(data => {
if (data.error) {
alert(data.error);
return;
}
displayGrid(data.grid);
})
.catch(error => console.error('Error:', error))
.finally(() => {
// Reset button text and enable it again
startButton.textContent = "Start";
startButton.disabled = false;
});
}, 2000); // 2-second delay
}
function displayGrid(grid) {
let resultDiv = document.getElementById("result");
resultDiv.innerHTML = "";
grid.forEach(row => {
let rowDiv = document.createElement("div");
rowDiv.textContent = row.join(" | ");
resultDiv.appendChild(rowDiv);
});
}