Less Distracting YouTube

Remove as many video suggestions as p

Fra 06.08.2024. Se den seneste versjonen.

// ==UserScript==
// @name         Less Distracting YouTube
// @namespace    http://tampermonkey.net/
// @version      2024-08-06.3
// @description  Remove as many video suggestions as p
// @author       Too___Tall
// @match        http*://m.youtube.com*
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function removeDistractions () {
        if (/^.*youtube.com\/?(?:#searching)?$/.test(window.location.href)) {
            try {document.querySelector("#app > .page-container").remove();} catch(e) {}
            try {document.querySelector("#contents").remove();} catch(e) {}
        } else if (/^.*youtube.com\/watch.*$/.test(window.location.href)) {
            try {document.querySelector("#app > div.page-container > ytm-watch > div.watch-below-the-player > ytm-single-column-watch-next-results-renderer > ytm-item-section-renderer").remove();} catch(e) {}
        }
        //Had some weird issue getting this to run with a check on window location, just running it last
        try {document.querySelector("#related").remove();} catch(e){}
    }

    //Fire it once when we load/change
    function intervalFunction () {
        let distractionInterval = window.setInterval(removeDistractions, 100);
    
        window.setTimeout(() => {window.clearInterval(distractionInterval)}, 10000);
    }
    intervalFunction();
    
    //Fire it on state change events
    window.addEventListener('hashchange',intervalFunction);
    window.addEventListener('popstate',intervalFunction);

})();