Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
Tampermonkey waitForKeyElements on successive YouTube videos

I have a script that currently does away with those pesky "Continue watching?" prompts on YouTube, using Tampermonkey and waitForKeyElements.

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:

enter image description here

I've heard this could be because YouTube replaces "history state" 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/"page changes"?

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)?

// ==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 ("#confirm-button.style-scope.yt-confirm-dialog-renderer.style-blue-text.size-default:contains('Yes')", clicks);

    function clicks (jNode) {
        var clickEvent = document.createEvent ('MouseEvents');
        clickEvent.initEvent ('click', true, true);
        jNode[0].dispatchEvent (clickEvent);
        console.log('SJ3');
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!