Created
April 11, 2023 01:05
-
-
Save Nezteb/a7a680b333d01b8b3be7aa1817981d27 to your computer and use it in GitHub Desktop.
[WIP] Remove Shorts and Lives from YouTube Subscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Remove Shorts and Lives from YouTube Subscriptions | |
// @description Remove Shorts and Lives from YouTube Subscriptions | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @author Noah Betzen | |
// @match https://www.youtube.com/feed/subscriptions | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// TODO: This doesn't work yet, still working on it... | |
const removeShortsAndLives = function() { | |
const container = document.querySelector('div#contents') | |
const videos = container.querySelectorAll('ytd-rich-item-renderer.style-scope.ytd-rich-grid-row') | |
console.log(`Found ${videos.length} videos`) | |
let elementsToRemove = [] | |
for (const video of videos) { | |
// querySelectorAll returns a NodeList object, so we check the length property | |
const isLive = video.querySelectorAll('ytd-badge-supported-renderer.video-badge.style-scope.ytd-rich-grid-media').length !== 0 | |
const isShort = video.querySelectorAll('ytd-thumbnail-overlay-time-status-renderer[overlay-style="SHORTS"]') | |
if (isLive || isShort) { | |
elementsToRemove.push(video) | |
} | |
} | |
const elementsToRemoveCount = elementsToRemove.length | |
for (const elementToRemove of elementsToRemove) { | |
elementToRemove.remove() | |
} | |
if (elementsToRemoveCount !== 0) { | |
console.log(`Removed ${elementsToRemoveCount} threads`); | |
} | |
} | |
let firstScrollHappened; | |
let isScrolling; | |
window.addEventListener('scroll', function (event) { | |
if(!firstScrollHappened) { | |
// Scrolling started | |
removeShortsAndLives() | |
} | |
firstScrollHappened = true | |
window.clearTimeout(isScrolling); | |
isScrolling = setTimeout(function() { | |
// Scrolling stopped | |
firstScrollHappened = false | |
removeShortsAndLives() | |
}, 50); | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment