Skip to content

Instantly share code, notes, and snippets.

@lbrooney
Last active December 7, 2023 00:59
Show Gist options
  • Save lbrooney/9f80de4ebb491aaf35a47a195e264b29 to your computer and use it in GitHub Desktop.
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
// ==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 },
);
@iRi-E
Copy link

iRi-E commented Dec 6, 2023

found typo in line 15.
s/YouTUbe/YouTube/

@lbrooney
Copy link
Author

lbrooney commented Dec 7, 2023

Should be fixed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment