Greasy Fork is available in English.

Обсуждения » Хотелки

Hide youtube videos older than 12 months (configurable)

It would be nice if you could hide youtube videos older than 12 months. This would eliminate videos that are years old appearing on the youtube homepage.

§
Создано: 25.02.2021
Отредактировано: 25.02.2021


// ==UserScript==
// @name Hide YT Videos = or older than a year
// @namespace HideOldYTVideos
// @version 0.1
// @description Hide YT Videos = or older than a year
// @author hacker09
// @match https://www.youtube.com/
// @icon https://www.youtube.com/s/desktop/daaab134/img/favicon.ico
// @run-at document-end
// @grant none
// ==/UserScript==

(function() {
'use strict';
function Hide(){ //Starts the function
var OldVideos = document.querySelectorAll("#metadata-line > span:nth-child(2)");
for (var i = OldVideos.length; i--;) { //For every video on the page
if (OldVideos[i].innerText.match('year') !== null) { //If the video was released 1 or more years from today
OldVideos[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = 'none'; //Hide the video
} //Finishes the if condition
} //Finishes the for condition
} //Finishes the function

Hide(); //Run the function to hide old videos when the youtube dashboard is loaded

window.onscroll = async function() { //Every time that the page it scrolled
Hide(); //Look for old videos and hide them
}; //Finishes the onscroll advent listener
})();

Thanks! Works great!

You're welcome

§
Создано: 26.02.2021
Отредактировано: 26.02.2021

I modified your script so that it hides videos older than a week, month, and year...

Also, it hides mixes now too.

I'm sure this can be further improved.

Also, for some reason, videos were not hiding at load, so I added a 2 second timeout to run the Hide() function in case Youtube takes a while to load.... seems to have resolved the issue for me.

// ==UserScript==
// @name Hide YT Videos by age and hide mixes
// @namespace HideOldYTVideos
// @version 0.2
// @description Hide YT Videos by age and hide mixes
// @author hacker09 (modified by Neil)
// @match https://www.youtube.com/
// @icon https://www.youtube.com/s/desktop/daaab134/img/favicon.ico
// @run-at document-end
// @grant none
// ==/UserScript==

(function() {
    'use strict';

    function Hide() { //Starts the function

        var videos = document.querySelectorAll("#contents > .ytd-rich-grid-renderer");
        for (var i = videos.length; i--;) { //For every video on the page

            var ageChild = videos[i].querySelector("#metadata-line > span:nth-child(2)"); //Find metadata line containing age of video

            if (ageChild !== null) {
                if ( (ageChild.innerText.match('year') !== null) || (ageChild.innerText.match('month') !== null) || (ageChild.innerText.match('week') !== null) ) { //If the video is older than a week, month, or year
                    videos[i].style.display = 'none'; //Hide the video
                } //Finishes the if condition
            }

            var mixChild = videos[i].querySelector("#video-title"); //Find video title

            if (mixChild !== null) {
                if ( (mixChild.innerText.match('Mix') !== null) ) { //If the video is a mix playlist
                    videos[i].style.display = 'none'; //Hide the mix playlist
                } //Finishes the if condition
            }




        } //Finishes the for condition


    } //Finishes the function

    Hide(); //Run the function to hide videos when the youtube dashboard is loaded

    setTimeout(function(){
        Hide() //Run the function to hide videos again 2 seconds after loading in case youtube hasn't finished loading yet...
    }, 2000);


    window.onscroll = async function() { //Every time that the page it scrolled
        Hide(); //Look for old videos or mixes and hide them
    }; //Finishes the onscroll advent listener


})();

Ответить

Войдите, чтобы ответить.