title: When timer reaches 0 click automatically on the button with Greasemonkey
body: <p>Here is an example of a timer <a href="http://www.prezzipazzi.com/prodotto.php?id=1809" rel="nofollow">http://www.prezzipazzi.com/prodotto.php?id=1809</a>
  and I need a code that when the timer reaches 0 it click automatically on the button1809.</p>
  
  <p>I tried this but it does not work:</p>
  
  <pre><code>var waitForZeroInterval = setInterval (CheckForZero, 0);
  var hasRun = false;
  
  function CheckForZero () {
  
      if ( (unsafeWindow.seconds == 0)  &amp;&amp;  (unsafeWindow.milisec == 0) )
      {
          clearInterval (waitForZeroInterval);
  
          var targButton  = document.getElementById ('bottone1809');
          var clickEvent  = document.createEvent ('MouseEvents');
  
          clickEvent.initEvent ('click', true, true);
          targButton.dispatchEvent (clickEvent);
      };
  
      if (!hasRun) {
          hasRun = true;
          setInterval(CheckForZero, 35000);
      };
  }
  </code></pre>