Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle background image loading and text element errors #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions foreground.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,42 @@ async function getImageBlob() {
let repeat = 0
while ((!document.querySelector("#root .screen img") || !document.querySelector('#root .screen button.button')) && repeat < 10) {
await new Promise(resolve => setTimeout(resolve, 1000))
repeat++
}
await new Promise(resolve => setTimeout(resolve, 1000))

if (document.querySelector('.match-game-alert')) return resolve(true)
if (document.querySelector('.match-game-alert')) return true

if (!document.querySelector("#root .screen img") || !document.querySelector('#root .screen button.button')) return false
return window.getComputedStyle(document.querySelector("#root .screen img"))
.getPropertyValue('background-image')
.match(/url\(["']?(.*?)["']?\)/)
.filter(item => !item.includes("url") && item.includes("blob:"))[0]

let attempts = 0;
let backgroundImage = '';
let matches = null;
let filteredUrls = null;

while (attempts < 20) { // 20 deneme yapacak
backgroundImage = window.getComputedStyle(document.querySelector("#root .screen img"))
.getPropertyValue('background-image');

if (backgroundImage && backgroundImage !== 'none') {
matches = backgroundImage.match(/url\(["']?(.*?)["']?\)/);

if (matches) {
filteredUrls = matches.filter(item => !item.includes("url") && item.includes("blob:"));
if (filteredUrls && filteredUrls.length > 0) {
console.log("Blob URL found:", filteredUrls[0]);
return filteredUrls[0];
}
}
}

console.log(`Attempt ${attempts + 1}/20: Waiting for background image...`);
await new Promise(resolve => setTimeout(resolve, 500));
attempts++;
}

console.log("Maximum attempts reached. Background image not found:", backgroundImage);
return false;
}

function createTask(base64Data, message) {
Expand Down Expand Up @@ -146,7 +172,15 @@ async function solveFuncaptcha() {
}
if (!blobData) whileStatus = false
let base64Data = await blobToBase64(blobData)
let result = await detectClickedLengh(base64Data, document.querySelector('[role="text"]').textContent)

const textElement = document.querySelector('[role="text"]');
if (!textElement) {
console.log("Text element not found, process might be completed");
whileStatus = false;
continue;
}

let result = await detectClickedLengh(base64Data, textElement.textContent)

if (document.querySelector('.match-game-alert')) {
simulateUserClick(document.querySelector('#root .screen button.button'))
Expand All @@ -167,4 +201,4 @@ async function solveFuncaptcha() {

window.onload = () => {
if (document.URL.includes("arkoselabs")) solveFuncaptcha()
}
}