Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ian4kasablancas/2f7e373206e19eec800be6711558d9d2 to your computer and use it in GitHub Desktop.

Select an option

Save ian4kasablancas/2f7e373206e19eec800be6711558d9d2 to your computer and use it in GitHub Desktop.
Hides members-only videos everywhere except the Members tab, where thumbnails are locked with overlay
// ==UserScript==
// @name YouTube Members-Only Filter & Lock Thumbnails
// @namespace yt-members-filter
// @version 1.0
// @description Hides members-only videos everywhere except the Members tab, where thumbnails are locked with overlay
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const MEMBER_TEXT_REGEX = /(members only|só para membros)/i;
// Inject lock overlay CSS
const style = document.createElement('style');
style.textContent = `
.yt-members-lock {
position: absolute;
inset: 0;
background: rgba(0,0,0,0.75);
display: flex;
align-items: center;
justify-content: center;
z-index: 5;
pointer-events: none;
}
.yt-members-lock svg {
width: 48px;
height: 48px;
fill: white;
opacity: 0.9;
}
ytd-thumbnail {
position: relative !important;
}
`;
document.head.appendChild(style);
function isMembersBadgePresent(video) {
return [...video.querySelectorAll('badge-shape')]
.some(b => MEMBER_TEXT_REGEX.test(b.innerText));
}
function isMembersTab() {
const url = location.href;
return url.includes('/membership') || url.includes('members');
}
function addLockOverlay(thumbnail) {
if (thumbnail.querySelector('.yt-members-lock')) return;
const lock = document.createElement('div');
lock.className = 'yt-members-lock';
lock.innerHTML = `
<svg viewBox="0 0 24 24">
<path d="M12 2a5 5 0 00-5 5v3H6a2 2 0 00-2 2v8a2 2 0 002 2h12a2 2 0 002-2v-8a2 2 0 00-2-2h-1V7a5 5 0 00-5-5zm-3 8V7a3 3 0 016 0v3H9z"/>
</svg>
`;
thumbnail.appendChild(lock);
}
function processVideos() {
const videos = document.querySelectorAll(
'ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer, ytd-compact-video-renderer'
);
videos.forEach(video => {
if (!isMembersBadgePresent(video)) return;
// Outside Members tab → hide completely
if (!isMembersTab()) {
video.style.display = 'none';
return;
}
// Inside Members tab → lock thumbnail
const thumbnail = video.querySelector('ytd-thumbnail');
if (thumbnail) {
addLockOverlay(thumbnail);
}
});
}
// Initial run
processVideos();
// Observe DOM changes (YouTube dynamic loading)
const observer = new MutationObserver(() => {
processVideos();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment