|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
document.getElementById('generator-form').addEventListener('submit', function(e) { |
|
e.preventDefault(); |
|
|
|
const numAccounts = document.getElementById('num_accounts').value; |
|
const startupRatio = document.getElementById('startup_ratio').value / 100; |
|
|
|
fetch('/start', { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
}, |
|
body: `num_accounts=${numAccounts}&startup_ratio=${startupRatio}` |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
if (data.status === 'success') { |
|
startProgressUpdates(); |
|
} else { |
|
alert(data.message); |
|
} |
|
}); |
|
}); |
|
|
|
|
|
document.getElementById('stop-btn').addEventListener('click', function() { |
|
fetch('/stop', { |
|
method: 'POST' |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
alert(data.message); |
|
}); |
|
}); |
|
|
|
|
|
function updateProgress() { |
|
fetch('/progress') |
|
.then(response => response.json()) |
|
.then(data => { |
|
const progressPercent = data.total > 0 ? Math.round((data.current / data.total) * 100) : 0; |
|
|
|
document.getElementById('progress-bar').style.width = `${progressPercent}%`; |
|
document.getElementById('progress-bar').textContent = `${progressPercent}%`; |
|
|
|
document.getElementById('total-count').textContent = data.total; |
|
document.getElementById('success-count').textContent = data.success; |
|
document.getElementById('failed-count').textContent = data.failed; |
|
|
|
document.getElementById('last-status').textContent = data.last_status; |
|
document.getElementById('last-username').textContent = data.last_username || '-'; |
|
|
|
document.getElementById('start-time').textContent = data.start_time || '-'; |
|
document.getElementById('end-time').textContent = data.end_time || '-'; |
|
}); |
|
} |
|
|
|
let progressInterval; |
|
|
|
function startProgressUpdates() { |
|
|
|
if (progressInterval) { |
|
clearInterval(progressInterval); |
|
} |
|
|
|
|
|
updateProgress(); |
|
|
|
|
|
progressInterval = setInterval(updateProgress, 2000); |
|
} |
|
|
|
|
|
updateProgress(); |
|
}); |