Skip to content

Instantly share code, notes, and snippets.

@frbaroni
Forked from xPaw/YoutubeHideWatched.user.js
Created September 7, 2021 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frbaroni/7652d14f265ef67e37652d25206369ab to your computer and use it in GitHub Desktop.
Save frbaroni/7652d14f265ef67e37652d25206369ab to your computer and use it in GitHub Desktop.
// ==UserScript==
// @version 1.4.0
// @name Hide watched videos on YouTube
// @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' && tagName !== 'ytd-rich-item-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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment