title: How to get a Tampermonkey script to wait for page to finish after a hashchange event?
body: <p>I'm writing a Tampermonkey script and I set up a listener for <code>hashchange</code>.<br>
  Inside that listener, I call a function that manipulates the DOM. The problem is that the function is called before the page is fully loaded. </p>
  
  <p>The page is not completely reloading when switching from one section to another so <code>on load</code> would only work once, that's why I'm listening for <code>hashchange</code> instead of <code>load</code>.</p>
  
  <pre><code>window.addEventListener('hashchange', function (e) {
      if (!/step=view&amp;ID=/.test(location.hash)) {
          //TODO clean up if leaving active trade
          return
      }
      console.log('hash changed', e)
      setup()
  });
  
  function setup() {
      //wait for page load here
      $('.myclass').after(&lt;span&gt;foo&lt;/span&gt;);
  }
  </code></pre>
  
  <p>I tried adding <code>on load</code> inside setup but that did nothing.</p>
  
  <p>Edit:</p>
  
  <p>Adding a listener for <code>load</code> outside <code>setup</code> would also work only once if going to the exact link, so that's not an option either.</p>