I'm doing some testing using Google ReCaptcha.
What I'm trying to do is to automatically click on the checkbox when the captcha appears. I took this teste()
function from the greasemonkey
site and it works perfectly using the plugin, but it does not work if I add it directly to my page.
Would anyone tell me why this is so? What does greasemonkey
do differently for script work?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script><scripttype='text/javascript'src='https://www.google.com/recaptcha/api.js'></script></head><bodyonload='test();'><formaction="hello" method="POST">
<div id='testid'>
<div class="g-recaptcha"
data-sitekey="SITE_KEY_HERE"
data-callback="onSuccess">
</div>
</div>
</form>
</body>
<script>
function test() {
var domain = (window.location != window.parent.location) ? document.referrer.toString() : document.location.toString();
if (domain.indexOf('miped.ru') == -1 && domain.indexOf('indiegala') == -1 && domain.indexOf('gleam.io') == -1) {
var clickCheck = setInterval(function() {
console.log('test');
if (document.querySelectorAll('.recaptcha-checkbox-checkmark').length > 0) {
clearInterval(clickCheck);
document.querySelector('.recaptcha-checkbox-checkmark').click();
}
}, 100);
}
}
var onSuccess = function(response) {
alert(grecaptcha.getResponse());
};
</script>
</html>