I have this userscript for GreaseMonkey. I created a function (A) which calls an other function (B). I want to wait running the A function further and wait for the B function to return. Function B contains a button, so in fact I want A to wait for the button press.
I tried this with the async and await but that didn't work for me show I now tried to use the .then() option. In the then() I created a function (nextI) to increase the i after running function B.
function A(){
    var i = 0
    while (i < 3){
        var data = jsonResponse[i];
        var x = data.x;
        var y = data.y;
        B(x, y).then(
            nextI(i)
        )
    }
)
function B(x, y){
    // do some stuff
    let button = document.getElementById("button");
    button.addEventListener("click", () => {
        console.log("Button clicked.");
        return
   });
}
function nextI(i){
    return i + 1
}
So I want to pause A until script B is done and I clicked the button.
 
     
    