Created
August 30, 2015 16:04
-
-
Save Danilnd/5376ef53238bf416710c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YandexAntiCaptcha | |
// @description Автоматический ввод яндекс капчи | |
// @author Danil (ParserExpert.ru) | |
// @version 1.0 | |
// @include http://yandex.ru/showcaptcha* | |
// ==/UserScript== | |
(function (window, undefined) { | |
var w; | |
if (typeof unsafeWindow != undefined) { | |
w = unsafeWindow | |
} else { | |
w = window; | |
} | |
// не запускаем скрипт во фреймах | |
if (w.self != w.top) { | |
return; | |
} | |
if (typeof String.prototype.startsWith != 'function') { | |
// see below for better implementation! | |
String.prototype.startsWith = function (str){ | |
return this.indexOf(str) === 0; | |
}; | |
} | |
var APIKEY = "123456789101234567891012345678910"; | |
document.querySelector('h1').innerHTML='Распознавание капчи ...'; | |
function _arrayBufferToBase64(buffer) { | |
var binary = ''; | |
var bytes = new Uint8Array(buffer); | |
var len = bytes.byteLength; | |
for (var i = 0; i < len; i++) { | |
binary += String.fromCharCode(bytes[i]); | |
} | |
return window.btoa(binary); | |
}; | |
function getCaptcha(url, callback){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
xhr.responseType = 'arraybuffer'; | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
var blob = this.response; | |
callback(_arrayBufferToBase64(blob)); | |
} | |
}; | |
xhr.send(); | |
} | |
function antiCaptcha(data, callback){ | |
var formData = new FormData(); | |
formData.append("key", APIKEY); | |
formData.append("method", "base64"); | |
formData.append("body", data); | |
formData.append("soft_id", 827); | |
GM_xmlhttpRequest({ | |
method: "POST", | |
url : "http://rucaptcha.com/in.php", | |
data: formData, | |
onload : function(x) { | |
ret = x.responseText; | |
console.log('API', ret); | |
if (ret.startsWith('OK|')){ | |
antiCaptchaRes(ret.replace('OK|', ''), callback); | |
}else if(ret=='ERROR_NO_SLOT_AVAILABLE'){ | |
// Нет слотов, ожидаем 5 сек и повторяем запрос | |
document.querySelector('h1').innerHTML='Нет доступных слотов' | |
setTimeout(function(){ antiCaptchaRes(data, callback) }, 5000); | |
}else{ | |
document.querySelector('h1').innerHTML=ret; | |
} | |
} | |
}); | |
} | |
function antiCaptchaRes(capid, callback){ | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url : 'http://rucaptcha.com/res.php?key='+APIKEY+'&action=get&id='+capid, | |
onload : function(x) { | |
ret = x.responseText; | |
console.log('API', ret); | |
if(ret=='CAPCHA_NOT_READY'){ | |
document.querySelector('h1').innerHTML='Ожидаем ответа ...'; | |
setTimeout(function(){ antiCaptchaRes(capid, callback) }, 1000); | |
}else{ | |
document.querySelector('h1').innerHTML='Ответ получен'; | |
callback(ret.replace('OK|', '')); | |
} | |
} | |
}); | |
} | |
var capurl = document.querySelector('img.form__captcha').src; | |
console.log('capurl', capurl); | |
getCaptcha(capurl, function(data){ | |
antiCaptcha(data, function(ret){ | |
document.querySelector('#rep').value=ret; | |
document.querySelector('.form__submit').click(); | |
}); | |
}); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment