2Captcha Demo
2Captcha Demo
Complete the captcha below:
// Replace the API_KEY with your actual 2Captcha API key
const API_KEY = "YOUR_API_KEY_HERE";
const SITE_KEY = "YOUR_SITE_KEY_HERE";
const SUBMIT_URL = "YOUR_SUBMIT_URL_HERE";
// Get a new captcha image and display it
function getCaptcha() {
const captchaImage = document.getElementById("captcha-image");
const captchaInput = document.getElementById("captcha-input");
// Make a GET request to the 2Captcha API to retrieve a new captcha image
fetch(`https://2captcha.com/in.php?key=${API_KEY}&method=userrecaptcha&googlekey=${SITE_KEY}&pageurl=${SUBMIT_URL}`)
.then(response => response.text())
.then(data => {
const captchaID = data.split("|")[1];
// Poll the 2Captcha API until the captcha is solved
const intervalID = setInterval(() => {
fetch(`https://2captcha.com/res.php?key=${API_KEY}&action=get&id=${captchaID}`)
.then(response => response.text())
.then(data => {
if (data === "CAPCHA_NOT_READY") {
// Captcha is not yet solved, do nothing
} else if (data.startsWith("OK")) {
// Captcha is solved, display the image and enable the submit button
const captchaResponse = data.split("|")[1];
captchaImage.src = `https://2captcha.com/res.php?key=${API_KEY}&action=download&id=${captchaResponse}`;
captchaInput.disabled = false;
document.getElementById("submit-button").disabled = false;
clearInterval(intervalID);
} else {
// Something went wrong, display the error message
const errorMessage = data;
document.getElementById("result").textContent = errorMessage;
clearInterval(intervalID);
}
})
.catch(error => {
// Something went wrong, display the error message
const errorMessage = error.message;
document.getElementById("result").textContent = errorMessage;
clearInterval(intervalID);
});
}, 3000);
})
.catch(error => {
// Something went wrong, display the error message
const errorMessage = error.message;
document.getElementById("result").textContent = errorMessage;
});
}
// Submit the captcha response to the server
function submitCaptcha() {
const captchaInput = document.getElementById("captcha-input");
// Make a POST request to the server with the captcha response
fetch(SUBMIT_URL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
captcha: captchaInput.value
})
})
.then(response => response.json())
.then(data => {
// Display the server's response
const result = data.result;
document.getElementById("result").textContent
Note: This code assumes that you have a 2Captcha API key, a reCAPTCHA site key, and a server that handles the captcha validation. Replace the placeholders in the JavaScript code with your actual values.
Note: This code assumes that you have a 2Captcha API key, a reCAPTCHA site key, and a server that handles the captcha validation. Replace the placeholders in the JavaScript code with your actual values.
// Replace the API_KEY with your actual 2Captcha API key
const API_KEY = "YOUR_API_KEY_HERE";
const SITE_KEY = "YOUR_SITE_KEY_HERE";
const SUBMIT_URL = "YOUR_SUBMIT_URL_HERE";
// Detect if the user has an ad blocker enabled
function detectAdBlocker() {
const adContainer = document.createElement("div");
adContainer.innerHTML = " ";
adContainer.className = "ad-div";
document.body.appendChild(adContainer);
const adBlocked = adContainer.offsetHeight === 0;
document.body.removeChild(adContainer);
return adBlocked;
}
// Get a new captcha image and display it
function getCaptcha() {
const captchaImage = document.getElementById("captcha-image");
const captchaInput = document.getElementById("captcha-input");
// Make a GET request to the 2Captcha API to retrieve a new captcha image
fetch(`https://2captcha.com/in.php?key=${API_KEY}&method=userrecaptcha&googlekey=${SITE_KEY}&pageurl=${SUBMIT_URL}`)
.then(response => response.text())
.then(data => {
const captchaID = data.split("|")[1];
// Poll the 2Captcha API until the captcha is solved
const intervalID = setInterval(() => {
fetch(`https://2captcha.com/res.php?key=${API_KEY}&action=get&id=${captchaID}`)
.then(response => response.text())
.then(data => {
if (data === "CAPCHA_NOT_READY") {
// Captcha is not yet solved, do nothing
} else if (data.startsWith("OK")) {
// Captcha is solved, display the image and enable the submit button
const captchaResponse = data.split("|")[1];
captchaImage.src = `https://2captcha.com/res.php?key=${API_KEY}&action=download&id=${captchaResponse}`;
captchaInput.disabled = false;
document.getElementById("submit-button").disabled = false;
clearInterval(intervalID);
} else {
// Something went wrong, display the error message
const errorMessage = data;
document.getElementById("result").textContent = errorMessage;
clearInterval(intervalID);
}
})
.catch(error => {
// Something went wrong, display the error message
const errorMessage = error.message;
document.getElementById("result").textContent = errorMessage;
clearInterval(intervalID);
});
}, 3000);
})
.catch(error => {
// Something went wrong, display the error message
const errorMessage = error.message;
document.getElementById("result").textContent = errorMessage;
});
}
// Submit the captcha response to the server
function submitCaptcha() {
const captchaInput = document.getElementById("captcha-input");
// Make a POST request to the server with the captcha response
fetch(SUBMIT_URL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
captcha: captchaInput.value
})
})
.then(response => response.json())
.then(data => {
// Display the server's response
const result = data.result;
document.getElementById("result").textContent = result;
})
.catch(error => {
// Something went wrong, display the error message
const errorMessage = error.message;
document.getElementById("result").textContent = errorMessage;
});
}
// Initialize the captcha when the page is loaded
window.addEventListener("load", () => {
if (detectAdBlocker()) {
// Ad blocker is detected, display a message and retry after 5 seconds
const adBlock
Comments
Post a Comment