Last active
December 7, 2023 00:59
-
-
Save lbrooney/9f80de4ebb491aaf35a47a195e264b29 to your computer and use it in GitHub Desktop.
A simple userscript that clicks the continue watching button on YouTube. Other solutions were overcomplicated or used intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube Continue Watching | |
// @description A simple userscript that clicks the continue watching button on YouTube. Other solutions were overcomplicated or used intervals | |
// @namespace https://roon.dev | |
// @license MIT | |
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/YouTube_full-color_icon_%282017%29.svg/320px-YouTube_full-color_icon_%282017%29.svg.png | |
// @match http*://www.youtube.com/watch* | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/lbrooney/9f80de4ebb491aaf35a47a195e264b29/raw/YouTube_Continue_Watching.user.js | |
// @updateURL https://gist.githubusercontent.com/lbrooney/9f80de4ebb491aaf35a47a195e264b29/raw/YouTube_Continue_Watching.user.js | |
// @version 0.1.2 | |
// @author Liam Rooney | lbrooney | |
// ==/UserScript== | |
console.log('[YTCW] YouTube Continue Watching Started.'); | |
// https://developers.google.com/youtube/iframe_api_reference | |
// for state and starting video | |
const observer = new MutationObserver(() => { | |
const confirmButton = document.getElementById('confirm-button'); | |
const player = document.getElementById('movie_player'); | |
if (confirmButton && player.getPlayerState() === 2) { // if confirmButton exists(it should) and the video is paused(it should be) | |
console.log(`[YTCW] Clicked yes to continue at ${(new Date()).toTimeString()}`); | |
confirmButton.click(); | |
player.playVideo(); // ensure video plays, should when yes clicked, but this guarantees. Might be unnecessary | |
} | |
}); | |
observer.observe( | |
document.getElementsByTagName('ytd-popup-container')[0], // observe popup(confirm button will be added as childNode) | |
{ attributes: true, childList: true, subtree: true }, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be fixed, thanks!