I don't know if the problem is asynchronous but my code didn't work here How do I get it to recheck every second on the else side if the if function in dat().then is false? Currently my dat() function in settimeout is not working. I didn't expect it to work anyway
var dat = async () => {
await document.querySelector("body").click();
}
dat().then(() => {
if(document.querySelector("body").className.indexOf("position") == -1){
console.log("right");
}
else setTimeout(arguments.callee, 1000);
})
dat();
Here's my attempt to write your code with the looping the stated desired loop.
var dat = async () => {
await document.querySelector("body").click();
}
const unclicked = () => (
document.querySelector("body").className.indexOf("position") == -1);
do {
await dat();
if (unclicked())
console.log("right");
else
setTimeout(arguments.callee, 1000);
} while (true)
However, I admit I agree with Kevin B's comment in that setTimeout and `document.querySelector(...).click() don't return Promises.
If you care to comment, I will gladly update the answer to reflect the question.