Skip to content

Instantly share code, notes, and snippets.

@gvoze32
Last active November 10, 2023 07:12
Show Gist options
  • Save gvoze32/9ad88e085d6b93c2b6a924cb3d061ad6 to your computer and use it in GitHub Desktop.
Save gvoze32/9ad88e085d6b93c2b6a924cb3d061ad6 to your computer and use it in GitHub Desktop.
satset jolly
async function automateProcess() {
for (let i = 0; i < 10000; i++) {
try {
console.log(`Iteration: ${i + 1}`);
const diamondsText = document.querySelector('div[style*="color: rgb(27, 67, 86);"][style*="font-size: 1rem;"][style*="margin-top: 0.5rem;"][style*="text-align: center;"]');
if (!diamondsText) {
console.error('Element with specified selector not found.');
continue;
}
const diamondsCount = parseInt(diamondsText.textContent.match(/\d+/)[0], 10);
console.log(`Diamonds count: ${diamondsCount}`);
let taskButtons = document.querySelectorAll('.task-button');
if (taskButtons.length === 0) {
console.error('No task buttons found.');
continue;
} else if (taskButtons.length === 1) {
console.log('Only one task button found. Clicking the first one.');
taskButtons[0].click();
} else {
taskButtons = Array.from(taskButtons).sort((a, b) => {
const rectA = a.getBoundingClientRect();
const rectB = b.getBoundingClientRect();
return rectA.left - rectB.left;
});
const taskButton1 = taskButtons[0];
const taskButton2 = taskButtons[1];
if (diamondsCount !== 0) {
console.log('Clicking task button 1');
taskButton1.click();
} else {
console.log('Clicking task button 2');
taskButton2.click();
}
}
console.log('Waiting for 2000 milliseconds');
await new Promise(resolve => setTimeout(resolve, 2000));
const closeButton = document.querySelector('.close-btn');
if (closeButton) {
console.log('Clicking close button');
const clickEvent = new Event('click');
closeButton.dispatchEvent(clickEvent);
} else {
console.error('Element with class "close-btn" not found.');
}
} catch (error) {
console.error('An error occurred:', error.message);
} finally {
console.log('Waiting for 2000 milliseconds before the next iteration');
await new Promise(resolve => setTimeout(resolve, 2000));
}
}
}
automateProcess();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment