Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>WhatsApp QR Code</title> | |
<style> | |
.button { | |
border: none; | |
color: white; | |
padding: 16px 32px; | |
text-align: center; | |
text-decoration: none; | |
display: inline-block; | |
font-size: 16px; | |
margin: 4px 2px; | |
transition-duration: 0.4s; | |
cursor: pointer; | |
} | |
.buttonGreen { | |
background-color: white; | |
color: black; | |
border: 2px solid #4CAF50; | |
} | |
.buttonGreen:hover { | |
background-color: #4CAF50; | |
color: white; | |
} | |
#qrCode { | |
display: block; | |
margin: 20px auto; | |
} | |
#statusText { | |
text-align: center; | |
color: blue; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>WhatsApp QR Code</h1> | |
<form id="authForm"> | |
<label for="idInstance">Id Instance:</label><br> | |
<input required type="text" id="idInstance" name="idInstance"><br> | |
<label for="apiTokenInstance">API Token:</label><br> | |
<input required type="text" id="apiTokenInstance" name="apiTokenInstance"><br><br> | |
<button type="submit" class="button buttonGreen">Get QR Code</button> | |
</form> | |
<p id="statusText"></p> | |
<img id="qrCode" src="" alt="QR Code" hidden> | |
<script> | |
document.getElementById("authForm").addEventListener("submit", function(event) { | |
event.preventDefault(); | |
const idInstance = document.getElementById("idInstance").value; | |
const apiTokenInstance = document.getElementById("apiTokenInstance").value; | |
const apiUrl = "https://apiUrl"; // Замените на фактический URL API | |
function updateQRCode() { | |
fetch(`${apiUrl}/waInstance${idInstance}/qr/${apiTokenInstance}`) | |
.then(response => response.json()) | |
.then(data => { | |
const qrCodeElement = document.getElementById("qrCode"); | |
const statusText = document.getElementById("statusText"); | |
if (data.type === 'qrCode') { | |
qrCodeElement.src = `data:image/png;base64,${data.message}`; | |
qrCodeElement.hidden = false; | |
statusText.textContent = ""; | |
} else if (data.type === 'error') { | |
qrCodeElement.hidden = true; | |
statusText.textContent = `Error: ${data.message}`; | |
} else if (data.type === 'alreadyLogged') { | |
qrCodeElement.hidden = true; | |
statusText.textContent = "Account already authorized."; | |
} | |
}) | |
.catch(error => { | |
console.error("Error fetching QR code:", error); | |
document.getElementById("statusText").textContent = "Error fetching QR code."; | |
}); | |
} | |
// Запуск обновления QR-кода каждую секунду | |
setInterval(updateQRCode, 1000); | |
updateQRCode(); // Вызов сразу после отправки формы | |
}); | |
</script> | |
</body> | |
</html> | |