Skip to content

Instantly share code, notes, and snippets.

@xPaw
Last active September 8, 2023 06:56
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xPaw/6324624 to your computer and use it in GitHub Desktop.
Save xPaw/6324624 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @version 1.4.1
// @name Hide watched videos on YouTube
// @icon https://www.youtube.com/favicon.ico
// @match https://www.youtube.com/*
// @exclude https://www.youtube.com/embed/*
// @exclude https://www.youtube.com/api/*
// @namespace https://gist.github.com/xPaw/6324624
// @updateURL https://gist.github.com/xPaw/6324624/raw/YoutubeHideWatched.user.js
// @downloadURL https://gist.github.com/xPaw/6324624/raw/YoutubeHideWatched.user.js
// @grant none
// ==/UserScript==
const app = document.querySelector( 'ytd-app' );
function HideVideos( a )
{
app.querySelectorAll( 'ytd-browse[page-subtype="subscriptions"] ytd-thumbnail-overlay-resume-playback-renderer' ).forEach( element =>
{
// Find the container element for this video
let tagName;
do
{
element = element.parentNode;
tagName = element.tagName.toLowerCase();
}
while( tagName !== 'ytd-grid-video-renderer' && tagName !== 'ytd-item-section-renderer' );
element.hidden = true;
} );
}
function ProcessPage()
{
if( !window.location.pathname.startsWith( '/feed/subscriptions' ) )
{
return;
}
const list = app.querySelector( 'ytd-section-list-renderer' );
if( list.dataset.hooked )
{
return;
}
list.dataset.hooked = true;
list.addEventListener( 'yt-next-continuation-data-updated', HideVideos );
// TODO: Find an event to fix this
new MutationObserver( HideVideos ).observe( list, { childList: true, subtree: true } );
}
if( app )
{
app.addEventListener( 'yt-navigate-finish', ProcessPage );
}
ProcessPage();
@MerlinScheurer
Copy link

Works now.
Thank you very much ;)

@alexandreraufast
Copy link

For those wondering, this script doesn't hide video permanently. If you reload, all videos will be back there.

@Osahashi
Copy link

It stops working for me/doesn't hide watched videos anymore, maybe YouTube change something? Could you please check/update the script? Thanks!

@Osahashi
Copy link

Osahashi commented Aug 28, 2021

Not working on the front page at the moment version 1.4.0

@frbaroni
Copy link

frbaroni commented Sep 7, 2021

Not working on the front page at the moment version 1.4.0

In order to make it work on homepage we need to include a new tagName to the filtering list:

change:
while( tagName !== 'ytd-grid-video-renderer' && tagName !== 'ytd-item-section-renderer' );

to:
while( tagName !== 'ytd-grid-video-renderer' && tagName !== 'ytd-item-section-renderer' && tagName !== 'ytd-rich-item-renderer' );

or get it at my fork https://gist.github.com/frbaroni/7652d14f265ef67e37652d25206369ab

@Osahashi
Copy link

Osahashi commented Sep 7, 2021

Not working on the front page at the moment version 1.4.0

In order to make it work on homepage we need to include a new tagName to the filtering list:

change:
while( tagName !== 'ytd-grid-video-renderer' && tagName !== 'ytd-item-section-renderer' );

to:
while( tagName !== 'ytd-grid-video-renderer' && tagName !== 'ytd-item-section-renderer' && tagName !== 'ytd-rich-item-renderer' );

or get it at my fork https://gist.github.com/frbaroni/7652d14f265ef67e37652d25206369ab

Thanks!

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