title: Tampermonkey/GreaseMonkey AutoClick -- other topics not helping
body: <p>I was wondering if anyone could help me create JavaScript for Tampermonkey on Chrome that will automatically click this button when the page loads.</p>
  
  <p>And here is the code for the button:</p>
  
  <pre><code>&lt;span id="container"&gt;
      &lt;input type="hidden" name="token" value="5216d2a45d4185bf3f0d156a145e5aed543717388f11a12000855403a0ced24cbe4ec2cd5327e43dd0a6ee66690de3f54c55625cddfe31131c4e0e498893bfe0"&gt;
      &lt;input type="button" class="btn-submit btn-blue large" id="button" value="Button"&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>Here is one of the things that I've tried:</p>
  
  <pre><code>var button = document.querySelector (
      "#button"
  );
  var clickEvent = document.createEvent ('MouseEvents');
  clickEvent.initEvent ('click', true, true);
  button.dispatchEvent (clickEvent);
  </code></pre>
  
  <p>and another</p>
  
  <pre><code>var btnShowObserver = function() {
    var button = document.getElementsByClassName('btn-submit')[0];
    button.getElementsByClassName('btn_confirm')[0].click();
  }
  </code></pre>
  
  <p>another</p>
  
  <pre><code>function myFunction() {
      document.getElementById("button").click();
  }
  </code></pre>
  
  <p>I have read things from 
  <a href="https://stackoverflow.com/questions/15048223/choosing-and-activating-the-right-controls-on-an-ajax-driven-site">Choosing and activating the right controls on an AJAX-driven site</a>
  to
  <a href="https://stackoverflow.com/questions/8192126/clicking-a-button-on-a-page-using-a-greasemonkey-userscript-in-chrome">Clicking a button on a page using a Greasemonkey/userscript in Chrome</a></p>
  
  <p>And I am still struggling I think it's something to do with the format of the button (it has no div and most code I've seen is referring to that.)</p>
  
  <p>Any ideas? I've tried my best but I am not overly familiar with javascript</p>