'How to refresh a page and click a button after random time using Tampermonkey

I am new to Javascript and I am trying to make a script in tampermonkey that will :

  1. Wait x min (x being a random number within a set interval)
  2. Refresh a specific page opened on the browser (google chrome)
  3. Wait a random time between 2 to 5 sec
  4. Click on a button
  5. Repeat the action from step 1.

I have found the source code of the button

<button type="button" value="Début" id="button61f10e221f8bb" class="textButtonV1 green startButton" onclick="Action" version="textButtonV1">
    Début</button> == $0

I have searched for guides / tutorial on internet to find the solution but I am struggling.

I understand that to click on the button the code would look like :

document.getElementById("button61f10e221f8bb").click();

But I don't know how to refresh the page, setp the loop, and make the script to wait x min before doing it.

Could you help me ?

EDIT 1:

I have continued my lessons on Javascript and so far I have been able to make two scripts. The first ones clicks on the button on a random interval (which changes after each click). And the second one refreshes the page every x minutes (x being random). Both scripts are working, however I am not yet where I want to be as I would need to "merge" the two to create the script I want. I will continue to work on it until I find the solution.

Script to click :

function click() {
  var buttons = document.getElementsByClassName("textButtonV1 green startButton");
  var randomTime = (Math.floor(Math.random() * (1500 - 900 + 1)) + 900) * 1000;
  for (let i = 0; i < buttons.length; i++) {
    if (buttons[i].value == "Début") {
      window.setTimeout(function () {
        buttons[i].click();
      }, 1000);
    }
  }
  window.setTimeout(click, randomTime);
}
click();

Script to refresh:

setTimeout(function(){ location.reload(); }, (Math.floor(Math.random() * (1500 - 900 + 1)) + 900) * 1000);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source