title: Tampermonkey waitForKeyElements on successive YouTube videos
body: <p>I have a script that currently does away with those pesky &quot;Continue watching?&quot; prompts on YouTube, using Tampermonkey and waitForKeyElements.</p>
  <p>However, it only seems to work if the prompt appears on the first YouTube video that I load (within the video, not between them). It doesn't seem to work for prompts on successive videos when I keep my autoplay going. When a prompt appears at the start of a new video, it doesn't seem to work at all. Here's what I'm talking about:</p>
  <p><a href="https://i.stack.imgur.com/m4Jym.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m4Jym.png" alt="enter image description here" /></a></p>
  <p>I've heard this could be because YouTube replaces &quot;history state&quot; and doesn't actually reload/change pages when going from one video to the next (please let me know if I'm wrong on this). How could I cater the following script to modern YouTube autoplay/&quot;page changes&quot;?</p>
  <p>Basically, how do I get the waitForKeyElements and function to fire every single time the prompt appears when I autoplay videos for an extended period of time (whether on the first video or another)?</p>
  <pre><code>// ==UserScript==
  // @name     YouTube Yes SJ3
  // @include  https://www.youtube.com/*
  // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
  // @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
  // @grant    GM_addStyle
  // ==/UserScript==
  
  waitForKeyElements (&quot;#confirm-button.style-scope.yt-confirm-dialog-renderer.style-blue-text.size-default:contains('Yes')&quot;, clicks);
  
      function clicks (jNode) {
          var clickEvent = document.createEvent ('MouseEvents');
          clickEvent.initEvent ('click', true, true);
          jNode[0].dispatchEvent (clickEvent);
          console.log('SJ3');
  }
  </code></pre>