Skip to content

Instantly share code, notes, and snippets.

@bnku
Last active June 10, 2023 08:27
Show Gist options
  • Save bnku/19303197eedc554af1215ff4c607b9f6 to your computer and use it in GitHub Desktop.
Save bnku/19303197eedc554af1215ff4c607b9f6 to your computer and use it in GitHub Desktop.
Hide shorts videos from youtube grid
// ==UserScript==
// @name Hide shorts videos from youtube subscription grid
// @namespace youtube.com
// @version 0.1
// @description
// ==/UserScript==
(function() {
'use strict';
const hide = ()=>{
//move switcher to top bar
document.querySelector('#end').appendChild(document.querySelectorAll('div#menu')[0])
//hide all shorts blocks
document.querySelectorAll('[overlay-style="SHORTS"]')
.forEach(v=>{
const vGrid = v.closest('ytd-rich-item-renderer')
if(vGrid) vGrid.style.display='none'
const vRow = v.closest('ytd-shelf-renderer')
if(vRow) vRow.parentNode.style.display='none'
})
}
// instahide
hide()
//lazyload observer
const observer = new ResizeObserver(entries => {
for (const entry of entries) {
hide()
}
})
observer.observe(document.querySelector('ytd-app'))
//location observer
const hrefObserver = new MutationObserver(function(mutations) {
let oldHref = document.location.href;
mutations.forEach(function(mutation) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
hide()
}
});
});
hrefObserver.observe(document.querySelector("body"), {
childList: true,
subtree: true
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment