-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcaptchas.js
130 lines (102 loc) · 3.66 KB
/
captchas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const solve = async (arguments) => {
const delay = async (ms) => {
await new Promise((resolve, reject) => {
setTimeout(() => resolve(), ms)
})
}
const get = async (url) => {
let response = new Promise((resolve, reject) => {
fetch(url).then(res => {
resolve(res.json())
}).catch(() => callback('BAD_FETCH'))
})
console.log(response)
return response
}
const waitForCaptcha = async (sitekey, method) => {
let key = method === 'hcaptcha' ? 'sitekey' : 'googlekey'
let api_url = `https://2captcha.com/in.php?header_acao=1&key=${api_key}&method=${method}&${key}=${sitekey}&json=1&pageurl=${document.location.href}&soft_id=2974`
let div = document.querySelector('[data-s]')
if(div){
api_url += `&data-s=${div.getAttribute('data-s')}`
}
let {status, request} = await get(api_url)
if(status) {
let result_url = `https://2captcha.com/res.php?header_acao=1&key=${api_key}&action=get&id=${request}&json=1&soft_id=2974`;
await delay(20000)
while(true){
response = await get(result_url)
console.log(response)
if(response.request === 'CAPCHA_NOT_READY'){
} else if (response.status === 1) {
break
} else {
return callback(response)
}
await delay(10000)
}
[...document.querySelectorAll('[name="h-captcha-response"],[name="g-recaptcha-response"]')].map(el => {
el.innerHTML = response.request;
})
setTimeout(() => {
let div = document.querySelector('[data-callback]')
if(div){
console.log('callback found')
window[div.getAttribute('data-callback')](response.request)
}
let form
if(method === 'hcaptcha'){
let el = document.querySelector('.h-captcha')
form = el ? el.closest('form') : document.querySelector('#challenge-form')
} else {
form = [...document.querySelectorAll('form')].find(f => f.querySelector('.g-recaptcha'))
}
if(form && options.submit !== false){
console.log('form found')
form.submit()
}
},100)
return callback('OK')
} else {
return callback(request)
}
}
const solveHcaptcha = async () => {
console.log('hcaptcha')
let sitekey = document.querySelector('[data-sitekey]') ?
document.querySelector('[data-sitekey]').getAttribute('data-sitekey') :
document.querySelector('iframe[src*=sitekey]').src.match(/[?&]sitekey=([\w-]+)/)[1]
console.log(sitekey)
await waitForCaptcha(sitekey, 'hcaptcha')
}
const solveRecaptcha = async () => {
console.log('recaptcha')
let sitekey = document.querySelector('[data-sitekey]') ?
document.querySelector('[data-sitekey]').getAttribute('data-sitekey') :
document.querySelector('iframe[src*=api2]').src.match(/[?&]k=(\w+)/)[1]
for(var iframe of document.querySelectorAll('iframe[src*=api2]')){
iframe.style.border = 'solid 3px green'
}
console.log(sitekey)
await waitForCaptcha(sitekey, 'userrecaptcha')
}
const solveCaptchas = async () => {
// look for hcaptcha / recaptcha\
// setTimeout(() => callback('Failed'), 60000)
let el = document.querySelector('.h-captcha')
let form = el ? el.closest('form') : document.querySelector('#challenge-form')
if(form){
return await solveHcaptcha()
}
let div = document.querySelector('.g-recaptcha,#g-recaptcha-response')
if(div){
return await solveRecaptcha()
}
callback('NO_CAPTCHAS')
}
const [api_key, options, callback] = arguments
await solveCaptchas()
}
if(typeof arguments !== 'undefined'){
solve(arguments)
}