How do I with a simple a jquery string in the console remove/restyle all elements that contain the innerHTML strings "years" and "months" on the youtube homescreen?
The goal is to remove or highlight all old video containers so i don't have to look at it and can focus on the new stuff since youtube recycle their content too much.
What i have done so far:
Step 1: First load jquery (works)
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();
Step 2 (fails): If i use ":contains" it remove everything and if i use ":has" nothing happens. How do i get it to not remove everything but only the specefic video elements?
$( "div:has('months')" ).css( "display", "none" );
This i the jQuery documentation i was following: https://api.jquery.com/category/selectors/content-filter-selector/
If any good ideas in how to clean up this homescreen please add a suggestion. With the Chrome "Multi Search & Multi Jump" plugin you can scroll to the bottom of the feed highlight all strings but would be much nicer to remove them all.
CodePudding user response:
Something like this perhaps (no need for jQuery) - tested in Chrome...
document.querySelectorAll('.ytd-video-meta-block').forEach(meta => { const metaText = meta.innerText; if(metaText.indexOf("month") !== -1 || metaText.indexOf("year") !== -1){ const old = meta.closest('.ytd-rich-grid-row'); if(old){ old.remove() }} })
