Skip to content

Instantly share code, notes, and snippets.

@kratzky
Last active June 3, 2025 00:47
Show Gist options
  • Save kratzky/20ea5f4f142cec8f1de748b3f3f84bfc to your computer and use it in GitHub Desktop.
Save kratzky/20ea5f4f142cec8f1de748b3f3f84bfc to your computer and use it in GitHub Desktop.
const getCaptchaData = () => {
return new Promise((resolve, reject)=>{
let canvas = document.createElement('canvas')
let ctx = canvas.getContext('2d')
let comment = document.querySelector('.rc-imageselect-desc-wrapper').innerText.replaceAll('\n', ' ')
let img4x4 = document.querySelector('img.rc-image-tile-44')
if (!img4x4) {
let table3x3 = document.querySelector('table.rc-imageselect-table-33 > tbody')
if (!table3x3) {
reject('Can not find reCAPTCHA elements')
}
initial3x3img = table3x3.querySelector('img.rc-image-tile-33')
canvas.width = initial3x3img.naturalWidth
canvas.height = initial3x3img.naturalHeight
ctx.drawImage(initial3x3img, 0, 0)
let updatedTiles = document.querySelectorAll('img.rc-image-tile-11')
if (updatedTiles.length > 0) {
const pos = [
{ x: 0, y: 0 }, { x: ctx.canvas.width / 3, y: 0 }, { x: ctx.canvas.width / 3 * 2, y: 0 },
{ x: 0, y: ctx.canvas.height / 3 }, { x: ctx.canvas.width / 3, y: ctx.canvas.height / 3 }, { x: ctx.canvas.width / 3 * 2, y: ctx.canvas.height / 3 },
{ x: 0, y: ctx.canvas.height / 3 * 2 }, { x: ctx.canvas.width / 3, y: ctx.canvas.height / 3 * 2 }, { x: ctx.canvas.width / 3 * 2, y: ctx.canvas.height / 3 * 2 }
]
updatedTiles.forEach((t) => {
const ind = t.parentElement.parentElement.parentElement.tabIndex - 3
ctx.drawImage(t, pos[ind - 1].x, pos[ind - 1].y)
})
}
resolve({
rows: 3,
columns: 3,
type: 'GridTask',
imgType: 'recaptcha',
comment,
body: canvas.toDataURL().replace(/^data:image\/?[A-z]*;base64,/, '')
})
} else {
canvas.width = img4x4.naturalWidth
canvas.height = img4x4.naturalHeight
ctx.drawImage(img4x4, 0, 0)
resolve({
rows: 4,
columns: 4,
comment,
body: canvas.toDataURL().replace(/^data:image\/?[A-z]*;base64,/, ''),
type: 'GridTask',
imgType: 'recaptcha'
})
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment