Skip to content

Instantly share code, notes, and snippets.

@leagris
Last active August 18, 2026 19:22
Show Gist options
  • Select an option

  • Save leagris/d4d52ab5b17cd762fcf911793e0f8dc1 to your computer and use it in GitHub Desktop.

Select an option

Save leagris/d4d52ab5b17cd762fcf911793e0f8dc1 to your computer and use it in GitHub Desktop.
This script removes each ytd-rich-section-renderer element that has an element with the id "dismissible". These sections usually show promoted content.
// ==UserScript==
// @name YouTube - Remove rich section with dismissible elements
// @namespace https://example.org/userscripts
// @version 1.1.0
// @author Léa Gris
// @license 0BSD
// @updateURL https://gist.github.com/leagris/d4d52ab5b17cd762fcf911793e0f8dc1/raw/yt-remove-rich-section.meta.js
// @downloadURL https://gist.github.com/leagris/d4d52ab5b17cd762fcf911793e0f8dc1/raw/yt-remove-rich-section.user.js
// @description This script removes each ytd-rich-section-renderer element that has an element with the id "dismissible". These sections usually show promoted content.
// @match https://www.youtube.com/*
// @match https://m.youtube.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
// ==UserScript==
// @name YouTube - Remove rich section with dismissible elements
// @namespace https://example.org/userscripts
// @version 1.1.0
// @author Léa Gris
// @license 0BSD
// @updateURL https://gist.github.com/leagris/d4d52ab5b17cd762fcf911793e0f8dc1/raw/yt-remove-rich-section.meta.js
// @downloadURL https://gist.github.com/leagris/d4d52ab5b17cd762fcf911793e0f8dc1/raw/yt-remove-rich-section.user.js
// @description This script removes each ytd-rich-section-renderer element that has an element with the id "dismissible". These sections usually show promoted content.
// @match https://www.youtube.com/*
// @match https://m.youtube.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
'use strict';
const RICH_SECTION = 'ytd-rich-section-renderer';
function hideDismissibleRichSections() {
if (!window.CSS?.supports?.('selector(:has(*))')) {
return;
}
const sheet = new CSSStyleSheet();
const index = sheet.insertRule(`${RICH_SECTION}:has([id="dismissible"]) {}`);
sheet.cssRules[index].style.setProperty('display', 'none', 'important');
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
}
function removeSectionIfDismissible(section) {
if (section.querySelector('#dismissible')) {
section.remove();
}
}
function onChildListMutationRemoveDismissibleSections(mutations) {
for (const mutation of mutations) {
// YouTube can put the dismissible element in the page after its section.
const parentSection = mutation.target.closest?.(RICH_SECTION);
if (parentSection) {
removeSectionIfDismissible(parentSection);
}
for (const node of mutation.addedNodes) {
if (node.nodeType !== Node.ELEMENT_NODE) {
continue;
}
if (node.matches(RICH_SECTION)) {
removeSectionIfDismissible(node);
}
for (const section of node.querySelectorAll(RICH_SECTION)) {
removeSectionIfDismissible(section);
}
}
}
}
hideDismissibleRichSections();
new MutationObserver(onChildListMutationRemoveDismissibleSections)
.observe(document.documentElement, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment