Skip to content

Instantly share code, notes, and snippets.

@DesertEagleDerek
Last active June 12, 2022 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DesertEagleDerek/20f4c08979347376d421bf41d952de76 to your computer and use it in GitHub Desktop.
Save DesertEagleDerek/20f4c08979347376d421bf41d952de76 to your computer and use it in GitHub Desktop.
Remove shorts from YouTube channel pages
// ==UserScript==
// @name YouTube shorts hider
// @namespace https://gist.githubusercontent.com/DesertEagleDerek/20f4c08979347376d421bf41d952de76/raw/YouTube_Shorts_Hider.user.js
// @updateURL https://gist.githubusercontent.com/DesertEagleDerek/20f4c08979347376d421bf41d952de76/raw/YouTube_Shorts_Hider.user.js
// @downloadURL https://gist.githubusercontent.com/DesertEagleDerek/20f4c08979347376d421bf41d952de76/raw/YouTube_Shorts_Hider.user.js
// @version 0.2
// @author DesertEagleDerek
// @description Remove shorts from YouTube channel pages
// @homepage http://www.deserteaglederek.com/
// @match https://www.youtube.com/c/*
// @run-at document-start
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==
//------------------------------------------------------------------------------------------------------------------------------
// DO NOT CHANGE ANYTHING ABOVE THIS LINE! FEEL FREE TO ENABLE OR DISABLE THE OPTIONS BELOW, THOUGH!
//------------------------------------------------------------------------------------------------------------------------------
var $startTimer = 500; /* time to wait before checking if the video grid renderer exists */
var $removeTimer = 500; /* time to wait before removing shorts after duplicate loaders have been removed */
//------------------------------------------------------------------------------------------------------------------------------
// DO NOT CHANGE ANYTHING BELOW THIS LINE! THIS IS WHERE ALL OF THE GEEKY CODE STUFF LIVES!
//------------------------------------------------------------------------------------------------------------------------------
/* globals jQuery */
/* globals $ */
var $observerAttached;
var $timerIdRefresh;
jQuery(document).ready(jQueryBegin);
function modifyPage() {
removeLoaders();
setTimeout(removeShorts, $removeTimer);
}
function removeShorts() {
// remove shorts
var $videos = $('ytd-grid-renderer').children('#items').children('ytd-grid-video-renderer').has('ytd-thumbnail-overlay-time-status-renderer[overlay-style="SHORTS"]');
$videos.each(function() {
$(this).remove();
});
}
function removeLoaders() {
// remove left over loading sections
var $loader = $('ytd-continuation-item-renderer');
if ($loader.length > 1) {
var current = 1;
$loader.each(function() {
if (current < $loader.length) {
$(this).remove();
current += 1;
}
});
}
}
function checkForRenderer() {
// content section loaded?
if ($('ytd-grid-renderer').length >= 1) {
// cancel element check timer
clearInterval($timerIdRefresh);
// remove initial shorts
modifyPage();
// monitor page for shorts loaded after scrolling
attachObserver();
}
}
function attachObserver() {
// select the target node
var target = document.querySelector('ytd-grid-renderer')
// create an observer instance
var observer = new MutationObserver(function(mutations) {
// this happens every time something changes
modifyPage();
});
// pass in the target node, as well as the observer options
observer.observe(target, {
attributes: true,
childList: true,
characterData: true
});
}
function jQueryBegin() {
// set timer to check for renderer element when the page is ready
$timerIdRefresh = setInterval(checkForRenderer, $startTimer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment