title: How to refresh a page and click a button after random time using Tampermonkey
body: <p>I am new to Javascript and I am trying to make a script in tampermonkey that will :</p>
  <ol>
  <li>Wait x min (x being a random number within a set interval)</li>
  <li>Refresh a specific page opened on the browser (google chrome)</li>
  <li>Wait a random time between 2 to 5 sec</li>
  <li>Click on a button</li>
  <li>Repeat the action from step 1.</li>
  </ol>
  <p>I have found the source code of the button</p>
  <pre><code>&lt;button type=&quot;button&quot; value=&quot;Début&quot; id=&quot;button61f10e221f8bb&quot; class=&quot;textButtonV1 green startButton&quot; onclick=&quot;Action&quot; version=&quot;textButtonV1&quot;&gt;
      Début&lt;/button&gt; == $0
  </code></pre>
  <p>I have searched for guides / tutorial on internet to find the solution but I am struggling.</p>
  <p>I understand that to click on the button the code would look like :</p>
  <pre><code>document.getElementById(&quot;button61f10e221f8bb&quot;).click();
  </code></pre>
  <p>But I don't know how to refresh the page, setp the loop, and make the script to wait x min before doing it.</p>
  <p>Could you help me ?</p>
  <p>EDIT 1:</p>
  <p>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 &quot;merge&quot; the two to create the script I want.
  I will continue to work on it until I find the solution.</p>
  <p>Script to click :</p>
  <pre><code>function click() {
    var buttons = document.getElementsByClassName(&quot;textButtonV1 green startButton&quot;);
    var randomTime = (Math.floor(Math.random() * (1500 - 900 + 1)) + 900) * 1000;
    for (let i = 0; i &lt; buttons.length; i++) {
      if (buttons[i].value == &quot;Début&quot;) {
        window.setTimeout(function () {
          buttons[i].click();
        }, 1000);
      }
    }
    window.setTimeout(click, randomTime);
  }
  click();
  </code></pre>
  <p>Script to refresh:</p>
  <pre><code>setTimeout(function(){ location.reload(); }, (Math.floor(Math.random() * (1500 - 900 + 1)) + 900) * 1000);
  </code></pre>