Removes experimental and featured recommendation sections from YouTube
// ==UserScript==
// @name YouTube - Hide Recommended Popups
// @description Removes experimental and featured recommendation sections from YouTube
// @namespace http://tampermonkey.net/
// @icon https://cdn-icons-png.flaticon.com/64/2504/2504965.png
// @version 0.0.5
// @author rxm
// @match https://www.youtube.com/*
// @license MIT
// @grant none
// ==/UserScript==
(() => {
'use strict';
const REMOVED_FLAG = 'data-yt-cleaned';
function isUnwantedSection(el) {
if (el.hasAttribute(REMOVED_FLAG)) return false;
return (
// Talk to Recs experiment
el.querySelector('ytd-talk-to-recs-flow-renderer') ||
// Experimental banners / promos
el.querySelector('#big-yoodle') ||
// Statement-style banners
el.tagName === 'YTD-STATEMENT-BANNER-RENDERER'
);
}
function removeIfUnwanted(el) {
if (isUnwantedSection(el)) {
el.setAttribute(REMOVED_FLAG, 'true');
el.remove();
console.debug('[YT Cleaner] Removed experimental recommendation section');
}
}
function scan(node) {
if (node.nodeType !== 1) return;
if (
node.matches?.(
'ytd-rich-section-renderer, ytd-statement-banner-renderer'
)
) {
removeIfUnwanted(node);
}
node.querySelectorAll?.(
'ytd-rich-section-renderer, ytd-statement-banner-renderer'
).forEach(removeIfUnwanted);
}
// Initial scan
scan(document.body);
// Observe only added nodes (much cheaper)
const observer = new MutationObserver(mutations => {
for (const m of mutations) {
for (const node of m.addedNodes) {
scan(node);
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})();