Skip to content

Instantly share code, notes, and snippets.

@jegor377
Last active January 4, 2023 20:22
Show Gist options
  • Save jegor377/23ca9510de687f47d058ef2da5a022be to your computer and use it in GitHub Desktop.
Save jegor377/23ca9510de687f47d058ef2da5a022be to your computer and use it in GitHub Desktop.
Removes YouTube Shorts from YouTube page on current tab. No section, not Shorts button.
// ==UserScript==
// @name Completely remove YouTube Shorts from page
// @namespace https://github.com/hallzy
// @version 0.2
// @description Removes YouTube Shorts Videos from your current page.
// @author Steven Hall, Igor Santarek
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
(
() =>
{
const removeShorts = () =>
{
const containers = [
'ytd-grid-video-renderer',
'ytd-video-renderer',
'ytd-rich-shelf-renderer',
];
containers
.forEach
(
container =>
{
const shorts= Array
.from(document.querySelectorAll(`${container} a[href^="/shorts"]`))
.forEach
(
a =>
{
const video = a.closest(container);
video.remove();
}
)
;
}
)
;
document.querySelector("ytd-guide-entry-renderer a[title='Shorts']").parentElement.remove();
}
const observer = new MutationObserver(removeShorts);
observer.observe
(
document,
{
childList: true,
subtree: true,
}
);
removeShorts();
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment