Create script.js
Browse files- templates/script.js +76 -0
templates/script.js
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.addEventListener('DOMContentLoaded', function() {
|
2 |
+
// Formulaire de génération
|
3 |
+
document.getElementById('generator-form').addEventListener('submit', function(e) {
|
4 |
+
e.preventDefault();
|
5 |
+
|
6 |
+
const numAccounts = document.getElementById('num_accounts').value;
|
7 |
+
const startupRatio = document.getElementById('startup_ratio').value / 100;
|
8 |
+
|
9 |
+
fetch('/start', {
|
10 |
+
method: 'POST',
|
11 |
+
headers: {
|
12 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
13 |
+
},
|
14 |
+
body: `num_accounts=${numAccounts}&startup_ratio=${startupRatio}`
|
15 |
+
})
|
16 |
+
.then(response => response.json())
|
17 |
+
.then(data => {
|
18 |
+
if (data.status === 'success') {
|
19 |
+
startProgressUpdates();
|
20 |
+
} else {
|
21 |
+
alert(data.message);
|
22 |
+
}
|
23 |
+
});
|
24 |
+
});
|
25 |
+
|
26 |
+
// Bouton d'arrêt
|
27 |
+
document.getElementById('stop-btn').addEventListener('click', function() {
|
28 |
+
fetch('/stop', {
|
29 |
+
method: 'POST'
|
30 |
+
})
|
31 |
+
.then(response => response.json())
|
32 |
+
.then(data => {
|
33 |
+
alert(data.message);
|
34 |
+
});
|
35 |
+
});
|
36 |
+
|
37 |
+
// Mettre à jour la progression
|
38 |
+
function updateProgress() {
|
39 |
+
fetch('/progress')
|
40 |
+
.then(response => response.json())
|
41 |
+
.then(data => {
|
42 |
+
const progressPercent = data.total > 0 ? Math.round((data.current / data.total) * 100) : 0;
|
43 |
+
|
44 |
+
document.getElementById('progress-bar').style.width = `${progressPercent}%`;
|
45 |
+
document.getElementById('progress-bar').textContent = `${progressPercent}%`;
|
46 |
+
|
47 |
+
document.getElementById('total-count').textContent = data.total;
|
48 |
+
document.getElementById('success-count').textContent = data.success;
|
49 |
+
document.getElementById('failed-count').textContent = data.failed;
|
50 |
+
|
51 |
+
document.getElementById('last-status').textContent = data.last_status;
|
52 |
+
document.getElementById('last-username').textContent = data.last_username || '-';
|
53 |
+
|
54 |
+
document.getElementById('start-time').textContent = data.start_time || '-';
|
55 |
+
document.getElementById('end-time').textContent = data.end_time || '-';
|
56 |
+
});
|
57 |
+
}
|
58 |
+
|
59 |
+
let progressInterval;
|
60 |
+
|
61 |
+
function startProgressUpdates() {
|
62 |
+
// Arrêter l'intervalle précédent s'il existe
|
63 |
+
if (progressInterval) {
|
64 |
+
clearInterval(progressInterval);
|
65 |
+
}
|
66 |
+
|
67 |
+
// Mettre à jour immédiatement
|
68 |
+
updateProgress();
|
69 |
+
|
70 |
+
// Puis toutes les 2 secondes
|
71 |
+
progressInterval = setInterval(updateProgress, 2000);
|
72 |
+
}
|
73 |
+
|
74 |
+
// Vérifier si une génération est déjà en cours au chargement de la page
|
75 |
+
updateProgress();
|
76 |
+
});
|