// ==UserScript== // @name Minimal Network (userscript) // @namespace minimal-network-userscript // @version 1.10.0 // @description Clean YouTube & X: no Shorts, ads, recommendations, end screens, trends, "For You" tab. Toggle everything from the userscript menu. // @match https://www.youtube.com/* // @match https://x.com/* // @match https://twitter.com/* // @run-at document-start // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @grant GM_addStyle // @grant GM_xmlhttpRequest // @connect returnyoutubedislikeapi.com // @updateURL https://raw.githubusercontent.com/gab-mod/minimal-network-mod/main/minimal-network.user.js // @downloadURL https://raw.githubusercontent.com/gab-mod/minimal-network-mod/main/minimal-network.user.js // ==/UserScript== (function () { 'use strict'; const IS_YT = location.hostname.endsWith('youtube.com'); const IS_X = !IS_YT; // ---------------------------------------------------------------- settings const OPTIONS = IS_YT ? [ ['yt_shorts', 'Hide Shorts (and open Shorts as normal videos)', true], ['yt_ads', 'Hide & skip ads (off: uBlock handles it)', false], ['yt_related', 'Hide recommended videos beside the player', true], ['yt_home', 'Hide home page feed', false], ['yt_endscreen', 'Hide end screens & cards', true], ['yt_comments', 'Hide comments', false], ['yt_news', 'Hide extra shelves on Home (news, topics…)', true], ['yt_chips', 'Hide topic chips bar on Home (Tudo, Jogos…)', true], ['yt_guideX', 'Hide sidebar "Explorar" & "Mais do YouTube"', true], ['yt_topnav', 'Home & Subscriptions buttons next to search', true], ['yt_livebtn', 'Live button (lives only) & no lives in Subscriptions', true], ['yt_topbar', 'Hide mic & "Criar" buttons', true], ['yt_compact', 'Compact cards (longer titles, no views)', true], ['yt_dislikes', 'Show dislike count (Return YouTube Dislike)', true], ['yt_glass', 'Glass layout (frosted bars & cards)', true], ['yt_mm', 'mod-midnight colours (T3 Code background, Zen colours)', true], ['yt_shortcuts', 'Minimal sidebar (Home, Subscriptions, You…)', true], ] : [ ['x_ads', 'Hide ads / promoted posts (off: uBlock handles it)', false], ['x_foryou', 'Hide "For You" tab (use Following)', true], ['x_trends', 'Hide trends', true], ['x_wtf', 'Hide "Who to follow"', true], ['x_reposts', 'Hide reposts', false], ['x_replies', 'Hide replies in home timeline', false], ]; const S = {}; for (const [key, , def] of OPTIONS) S[key] = GM_getValue(key, def); for (const [key, label] of OPTIONS) { GM_registerMenuCommand(`${S[key] ? '✅' : '⬜'} ${label}`, () => { GM_setValue(key, !S[key]); location.reload(); }); } // Non-boolean YouTube settings const BG_PRESETS = { midnight: 'radial-gradient(at 20% 15%, #4b1d8f 0, transparent 50%), radial-gradient(at 85% 75%, #2e0f5c 0, transparent 50%), radial-gradient(at 60% 30%, #1a0b33 0, transparent 60%), #07050d', aurora: 'radial-gradient(at 15% 20%, #6d4aff 0, transparent 45%), radial-gradient(at 85% 10%, #00c2a8 0, transparent 40%), radial-gradient(at 70% 85%, #ff4f9a 0, transparent 45%), #14112b', sunset: 'radial-gradient(at 20% 15%, #ff9a3c 0, transparent 45%), radial-gradient(at 80% 30%, #ff3c6e 0, transparent 45%), radial-gradient(at 50% 95%, #7b2cbf 0, transparent 50%), #2a1022', ocean: 'radial-gradient(at 10% 80%, #0077b6 0, transparent 50%), radial-gradient(at 80% 20%, #00b4d8 0, transparent 45%), radial-gradient(at 60% 70%, #023e8a 0, transparent 50%), #03142b', forest: 'radial-gradient(at 20% 20%, #2d6a4f 0, transparent 45%), radial-gradient(at 85% 60%, #95d5b2 0, transparent 40%), radial-gradient(at 40% 95%, #1b4332 0, transparent 50%), #0b1f16', }; if (IS_YT) { S.yt_bg = GM_getValue('yt_bg', 'midnight'); S.yt_relatedWidth = GM_getValue('yt_relatedWidth', 0); if (S.yt_glass) { const bgLabel = BG_PRESETS[S.yt_bg] || S.yt_bg === 'none' ? S.yt_bg : 'custom image'; GM_registerMenuCommand(`🖼 Background: ${bgLabel}`, () => { const v = prompt( 'Background: type midnight, aurora, sunset, ocean, forest or none — or paste an image URL (https://…)', S.yt_bg ); if (v == null) return; const val = v.trim(); if (BG_PRESETS[val.toLowerCase()] || val.toLowerCase() === 'none') GM_setValue('yt_bg', val.toLowerCase()); else if (/^https?:\/\//i.test(val)) GM_setValue('yt_bg', val); else return alert('Not recognised — use a preset name or an image URL.'); location.reload(); }); } GM_registerMenuCommand( `↔ Recommendations width: ${S.yt_relatedWidth ? S.yt_relatedWidth + 'px' : 'default'}`, () => { const v = prompt('Width of the column beside the video, in px (e.g. 300–600). Leave empty for default.', S.yt_relatedWidth || ''); if (v == null) return; const n = parseInt(v, 10); GM_setValue('yt_relatedWidth', Number.isFinite(n) && n >= 200 && n <= 1000 ? n : 0); location.reload(); } ); S.yt_perRow = GM_getValue('yt_perRow', 5); GM_registerMenuCommand(`▦ Videos per row: ${S.yt_perRow || 'default'}`, () => { const v = prompt('Videos per row on Home / Subscriptions (2–8). Leave empty for YouTube default.', S.yt_perRow || ''); if (v == null) return; const n = parseInt(v, 10); GM_setValue('yt_perRow', Number.isFinite(n) && n >= 2 && n <= 8 ? n : 0); location.reload(); }); } // ------------------------------------------------------------------- utils const css = []; const hide = (selectors) => css.push(`${selectors.join(',\n')} { display: none !important; }`); function throttle(fn) { let queued = false; return () => { if (queued) return; queued = true; requestAnimationFrame(() => { queued = false; fn(); }); }; } function observe(fn) { const run = throttle(fn); const start = () => { new MutationObserver(run).observe(document.body, { childList: true, subtree: true }); run(); }; document.body ? start() : document.addEventListener('DOMContentLoaded', start); } // ================================================================= YOUTUBE if (IS_YT) { if (S.yt_shorts) { hide([ 'ytd-reel-shelf-renderer', 'ytd-rich-shelf-renderer[is-shorts]', 'ytd-rich-section-renderer:has(ytd-rich-shelf-renderer[is-shorts])', 'grid-shelf-view-model:has(ytm-shorts-lockup-view-model)', 'grid-shelf-view-model:has(ytm-shorts-lockup-view-model-v2)', 'ytd-rich-section-renderer:has(grid-shelf-view-model)', 'ytd-rich-item-renderer:has(a[href^="/shorts/"])', 'ytd-video-renderer:has(a[href^="/shorts/"])', 'ytd-grid-video-renderer:has(a[href^="/shorts/"])', 'ytd-compact-video-renderer:has(a[href^="/shorts/"])', 'yt-lockup-view-model:has(a[href^="/shorts/"])', 'ytd-guide-entry-renderer:has(a[title="Shorts"])', 'ytd-mini-guide-entry-renderer[aria-label="Shorts"]', 'yt-tab-shape[tab-title="Shorts"]', ]); // Open any Shorts link as a regular video const redirectShorts = () => { const m = location.pathname.match(/^\/shorts\/([\w-]+)/); if (m) location.replace(`/watch?v=${m[1]}`); }; redirectShorts(); window.addEventListener('yt-navigate-start', redirectShorts); window.addEventListener('yt-navigate-finish', redirectShorts); } if (S.yt_ads) { hide([ '#masthead-ad', 'ytd-ad-slot-renderer', 'ytd-in-feed-ad-layout-renderer', 'ytd-rich-item-renderer:has(ytd-ad-slot-renderer)', 'ytd-banner-promo-renderer', 'ytd-statement-banner-renderer', 'ytd-promoted-sparkles-web-renderer', 'ytd-promoted-video-renderer', 'ytd-display-ad-renderer', 'ytd-companion-slot-renderer', 'ytd-player-legacy-desktop-watch-ads-renderer', '#player-ads', 'ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-ads"]', '.ytp-ad-overlay-container', '.ytp-ad-image-overlay', 'ytd-merch-shelf-renderer', ]); // Skip video ads: jump to their end and press "Skip" when it appears setInterval(() => { const player = document.querySelector('.html5-video-player.ad-showing'); if (!player) return; const video = player.querySelector('video'); if (video && isFinite(video.duration) && video.duration > 0) { video.currentTime = video.duration; } player .querySelector('.ytp-skip-ad-button, .ytp-ad-skip-button, .ytp-ad-skip-button-modern') ?.click(); }, 300); } if (S.yt_related) { hide(['#related', 'ytd-watch-next-secondary-results-renderer']); } if (S.yt_home) { hide(['ytd-browse[page-subtype="home"] ytd-rich-grid-renderer']); } if (S.yt_endscreen) { hide([ '.ytp-ce-element', '.ytp-endscreen-content', '.html5-endscreen', '.ytp-videowall-still', '.ytp-fullscreen-grid', '.ytp-pause-overlay', ]); } if (S.yt_comments) { hide(['ytd-comments#comments']); } if (S.yt_news) { const NEWS_RE = /^(principais notícias|notícias de última hora|últimas notícias|top news|breaking news|noticias principales|noticias de última hora)$/i; const SHELVES = 'ytd-rich-shelf-renderer, ytd-shelf-renderer, ytd-horizontal-card-list-renderer, ytd-reel-shelf-renderer'; const hideNews = () => { document.querySelectorAll(SHELVES).forEach((shelf) => { const title = shelf.querySelector('#title, #title-text, h2'); if (!title || !NEWS_RE.test(title.textContent.trim())) return; const box = shelf.closest('ytd-rich-section-renderer, ytd-item-section-renderer') || shelf; box.style.setProperty('display', 'none', 'important'); }); }; observe(hideNews); // Every extra shelf on Home (news, "Descoberta avançada de novos temas", etc.) hide([ 'ytd-browse[page-subtype="home"] ytd-rich-section-renderer', 'ytd-browse[page-subtype="subscriptions"] ytd-rich-section-renderer', // "Mais relevantes" ]); } if (S.yt_topbar) { hide([ '#voice-search-button', 'ytd-masthead #buttons > :has([aria-label="Criar"])', 'ytd-masthead #buttons > :has([aria-label="Create"])', ]); } if (S.yt_chips) { hide([ 'ytd-browse[page-subtype="home"] ytd-feed-filter-chip-bar-renderer', 'ytd-browse[page-subtype="home"] #header.ytd-rich-grid-renderer', ]); css.push(`#frosted-glass.with-chipbar.ytd-app { height: 56px !important; }`); } if (S.yt_guideX) { hide([ 'ytd-guide-entry-renderer:has(a[href="/reporthistory"])', 'ytd-guide-renderer #footer', ]); const GUIDE_RE = /^(explorar|explore|mais do youtube|more from youtube)$/i; const hideGuide = () => { document.querySelectorAll('ytd-guide-section-renderer').forEach((sec) => { const t = sec.querySelector('#guide-section-title'); if (t && GUIDE_RE.test(t.textContent.trim())) sec.style.setProperty('display', 'none', 'important'); }); }; observe(hideGuide); } if (S.yt_dislikes) { css.push(` .mn-dislikes { margin-left: 6px; font-size: 14px; font-weight: 500; white-space: nowrap; } `); const cache = new Map(); const fmt = new Intl.NumberFormat(undefined, { notation: 'compact', maximumFractionDigits: 1 }); const videoId = () => location.pathname === '/watch' ? new URLSearchParams(location.search).get('v') : null; const fetchDislikes = (id) => new Promise((resolve) => { if (cache.has(id)) return resolve(cache.get(id)); GM_xmlhttpRequest({ method: 'GET', url: `https://returnyoutubedislikeapi.com/votes?videoId=${encodeURIComponent(id)}`, onload: (r) => { try { const n = JSON.parse(r.responseText).dislikes; cache.set(id, n); resolve(n); } catch { resolve(null); } }, onerror: () => resolve(null), }); }); let busy = false; const paint = async () => { const id = videoId(); if (!id || busy) return; const btn = document.querySelector( 'ytd-watch-metadata dislike-button-view-model button, ytd-watch-metadata #segmented-dislike-button button' ); if (!btn) return; const existing = btn.querySelector('.mn-dislikes'); if (existing && existing.dataset.vid === id) return; busy = true; const n = await fetchDislikes(id); busy = false; if (n == null || videoId() !== id) return; const span = existing || document.createElement('span'); span.className = 'mn-dislikes'; span.dataset.vid = id; span.textContent = fmt.format(n); if (!existing) { btn.classList.remove('yt-spec-button-shape-next--icon-button'); btn.classList.add('yt-spec-button-shape-next--icon-leading'); btn.appendChild(span); } }; window.addEventListener('yt-navigate-finish', paint); setInterval(paint, 1000); } } // ========================================================= YOUTUBE DESIGN if (IS_YT && S.yt_glass) { let bg = 'none'; if (BG_PRESETS[S.yt_bg]) bg = BG_PRESETS[S.yt_bg]; else if (/^https?:\/\//i.test(S.yt_bg)) bg = `url("${S.yt_bg.replace(/["\\\n]/g, '')}") center / cover no-repeat, #111`; css.push(` html { --mn-glass: rgba(255, 255, 255, 0.55); --mn-glass-strong: rgba(255, 255, 255, 0.72); --mn-border: rgba(255, 255, 255, 0.55); --mn-blur: blur(16px) saturate(1.5); } html[dark] { --mn-glass: rgba(20, 20, 28, 0.45); --mn-glass-strong: rgba(20, 20, 28, 0.55); --mn-border: rgba(255, 255, 255, 0.10); } /* YouTube paints its solid colour through these variables — make them see-through */ html, html[dark], html[dark] [dark], ytd-app, ytd-app[dark] { --yt-spec-base-background: transparent !important; --yt-spec-general-background-a: transparent !important; --yt-spec-general-background-b: transparent !important; --yt-spec-general-background-c: transparent !important; --yt-spec-brand-background-solid: transparent !important; --yt-spec-brand-background-primary: transparent !important; --yt-spec-brand-background-secondary: transparent !important; --yt-frosted-glass-desktop: transparent !important; } /* Blurred picture behind the page (a fixed layer, so it never scrolls) */ html, html[dark] { background: #0b0b10 !important; } body { background: transparent !important; } body::before { content: ""; position: fixed; inset: -60px; z-index: -1; pointer-events: none; background: ${bg}; filter: blur(${/^https?:/i.test(S.yt_bg) ? 28 : 12}px) saturate(1.3); } html[dark] body::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; background: rgba(0, 0, 0, .25); } ytd-app, #content.ytd-app, ytd-page-manager, ytd-browse, ytd-search, ytd-watch-flexy, ytd-two-column-browse-results-renderer, #contents.ytd-rich-grid-renderer, ytd-section-list-renderer, ytd-item-section-renderer, #header.ytd-rich-grid-renderer, ytd-playlist-video-list-renderer, ytd-page-header-renderer, ytd-c4-tabbed-header-renderer, #tabs-inner-container, ytd-two-column-browse-results-renderer, ytd-rich-grid-renderer, #frosted-glass, ytd-feed-filter-chip-bar-renderer #chips-wrapper, #columns, #primary, #secondary, ytd-tabbed-page-header, #page-header-container, tp-yt-app-header #background { background: transparent !important; } /* Frosted top bar & sidebar */ #masthead-container.ytd-app, #frosted-glass.ytd-app { background: var(--mn-glass-strong) !important; backdrop-filter: var(--mn-blur); border-bottom: 1px solid var(--mn-border); } ytd-masthead #background, ytd-masthead { background: transparent !important; } tp-yt-app-drawer #contentContainer, ytd-guide-renderer, ytd-mini-guide-renderer { background: var(--mn-glass) !important; backdrop-filter: var(--mn-blur); } /* Frosted cards */ ytd-rich-item-renderer > #content, ytd-video-renderer, ytd-playlist-renderer, ytd-channel-renderer, ytd-grid-video-renderer, #secondary yt-lockup-view-model, ytd-compact-video-renderer { background: var(--mn-glass) !important; backdrop-filter: var(--mn-blur); border: 1px solid var(--mn-border); border-radius: 18px; padding: 8px; box-sizing: border-box; transition: transform .18s ease, box-shadow .18s ease; } ytd-rich-item-renderer > #content:hover, ytd-video-renderer:hover, #secondary yt-lockup-view-model:hover, ytd-compact-video-renderer:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); } ytd-video-renderer { margin-bottom: 12px; } /* Frosted panels on the watch page */ ytd-watch-metadata, ytd-comments#comments, ytd-playlist-panel-renderer #container, ytd-live-chat-frame { background: var(--mn-glass) !important; backdrop-filter: var(--mn-blur); border: 1px solid var(--mn-border); border-radius: 18px; } ytd-watch-metadata { padding: 12px 16px; margin-top: 12px; box-sizing: border-box; } ytd-comments#comments { padding: 12px 16px; margin-top: 12px; } #movie_player, #ytd-player { border-radius: 18px; overflow: hidden; } `); } // ===================================================== MOD-MIDNIGHT COLOURS // Palette: github.com/gab-mod/zenmods-mod (mod-midnight). Page = T3 Code chat area, // bars/sidebar/hover/selected/accent = the Zen mod (Mod Zen Tweaks). if (IS_YT && S.yt_mm) { css.push(` html[dark], html[dark] [dark], ytd-app[dark] { --mm-base: #242029; /* T3 Code chat area */ --mm-sidebar: #1f1920; /* Zen sidebar */ --mm-row: #2d2539; /* Zen selected tab */ --mm-hover: #28222f; /* Zen hover */ --mm-control: #362d3d; /* Zen surface */ --mm-control-hover: #463753; --mm-border: #322028; /* Zen border */ --mm-text: #fafafc; --mm-subtext: #d4c7e1; --mm-focus: #574478; /* Zen accent (purple, 1.10.0) */ --mm-accent: #45325f; /* buttons */ --mm-selection: #3d3052; --mm-link: #c4a7f0; --mm-on-accent: #f1e8ff; --yt-spec-base-background: var(--mm-base) !important; --yt-spec-general-background-a: var(--mm-base) !important; --yt-spec-general-background-b: var(--mm-base) !important; --yt-spec-general-background-c: var(--mm-base) !important; --yt-spec-brand-background-solid: var(--mm-sidebar) !important; --yt-spec-brand-background-primary: var(--mm-sidebar) !important; --yt-spec-brand-background-secondary: var(--mm-sidebar) !important; --yt-frosted-glass-desktop: var(--mm-sidebar) !important; --yt-spec-raised-background: var(--mm-sidebar) !important; --yt-spec-menu-background: var(--mm-sidebar) !important; --yt-spec-text-primary: var(--mm-text) !important; --yt-spec-text-secondary: var(--mm-subtext) !important; --yt-spec-10-percent-layer: var(--mm-border) !important; --yt-spec-badge-chip-background: var(--mm-control) !important; --yt-spec-button-chip-background-hover: var(--mm-control-hover) !important; --yt-spec-call-to-action: var(--mm-link) !important; --mn-glass: var(--mm-row) !important; --mn-glass-strong: var(--mm-sidebar) !important; --mn-border: var(--mm-border) !important; } html[dark] { background: var(--mm-base) !important; } html[dark] body::before { background: var(--mm-base) !important; filter: none !important; } html[dark] body::after { display: none !important; } /* YouTube's left sidebar has no colour of its own: it sits on the page colour, so there is no extra bar next to Zen's sidebar */ html[dark] tp-yt-app-drawer #contentContainer, html[dark] ytd-guide-renderer, html[dark] ytd-mini-guide-renderer, html[dark] ytd-mini-guide-entry-renderer { background: var(--mm-base) !important; backdrop-filter: none !important; border: 0 !important; } html[dark] ::selection { background: var(--mm-selection); color: var(--mm-text); } /* cards: Zen surface on hover */ html[dark] ytd-rich-item-renderer > #content:hover, html[dark] ytd-video-renderer:hover, html[dark] #secondary yt-lockup-view-model:hover, html[dark] ytd-compact-video-renderer:hover { background: var(--mm-control) !important; } /* progress bar and the red bits of the player in the accent */ .ytp-play-progress, .ytp-swatch-background-color, .ytp-volume-slider-handle, .ytp-volume-slider-handle::before, #progress.ytd-thumbnail-overlay-resume-playback-renderer { background: var(--mm-focus) !important; } /* top buttons and minimal sidebar like Zen tabs */ html[dark] #mn-topnav a { background: var(--mm-control) !important; color: var(--mm-text) !important; } html[dark] #mn-topnav a:hover { background: var(--mm-control-hover) !important; } html[dark] #mn-topnav a.mn-active:not(.mn-live) { background: var(--mm-accent) !important; color: var(--mm-on-accent) !important; } html[dark] #mn-shortcuts a { color: var(--mm-text) !important; } html[dark] #mn-shortcuts a:hover { background: var(--mm-hover) !important; } html[dark] #mn-shortcuts a.mn-active { background: var(--mm-row) !important; box-shadow: inset 3px 0 0 var(--mm-focus); } html[dark] #mn-shortcuts hr { border-top-color: var(--mm-border) !important; } `); } if (IS_YT && S.yt_perRow) { const n = S.yt_perRow; css.push(` ytd-rich-grid-renderer { --ytd-rich-grid-items-per-row: ${n} !important; --ytd-rich-grid-posts-per-section: ${n} !important; --ytd-rich-grid-slim-items-per-row: ${n} !important; } /* Older layout groups videos in fixed rows — flatten them so the count applies */ ytd-rich-grid-row, ytd-rich-grid-row > #contents { display: contents !important; } ytd-rich-grid-renderer #contents.ytd-rich-grid-renderer { flex-wrap: wrap !important; } /* Tighter spacing: 12px between cards, both ways */ ytd-rich-grid-renderer ytd-rich-item-renderer[rendered-from-rich-grid] { width: calc(100% / ${n} - 12px) !important; max-width: none !important; margin: 0 6px 12px !important; } ytd-rich-grid-renderer #contents.ytd-rich-grid-renderer { margin: 0 -6px !important; padding-top: 12px !important; } `); } // Compact cards: longer titles, smaller avatar, no view count if (IS_YT && S.yt_compact) { const G = 'ytd-rich-grid-renderer'; css.push(` ${G} #video-title, ${G} #video-title-link, ${G} .yt-lockup-metadata-view-model__title, ${G} .yt-lockup-metadata-view-model__title *, ${G} [class*="lockup-metadata-view-model"] h3, ${G} [class*="lockup-metadata-view-model"] h3 * { font-size: 1.3rem !important; line-height: 1.75rem !important; -webkit-line-clamp: 4 !important; line-clamp: 4 !important; max-height: none !important; } ${G} #avatar-container, ${G} #avatar-link, ${G} #avatar-link yt-img-shadow, ${G} #avatar-link img, ${G} .yt-lockup-metadata-view-model__avatar, ${G} .yt-lockup-metadata-view-model__avatar yt-avatar-shape, ${G} .yt-lockup-metadata-view-model__avatar .yt-spec-avatar-shape, ${G} .yt-lockup-metadata-view-model__avatar img { width: 24px !important; height: 24px !important; min-width: 24px !important; } ${G} #avatar-container, ${G} .yt-lockup-metadata-view-model__avatar { margin-right: 8px !important; } `); // "367 mil", "▷ 1,5 mi", "1.234 visualizações", "23 assistindo", "Sem visualizações"… const VIEWS_RE = /^[^\p{L}\p{N}]*([\d.,\s]+(mil|mi|bi|k|m|b|mln|mld)?\.?\s*(de\s+)?(visualizaç(ão|ões)|views?|assistindo|watching|espectadores)?|sem visualizações|no views)$/iu; const CARDS = 'ytd-rich-item-renderer, ytd-grid-video-renderer, ytd-video-renderer'; const NOTIFY_RE = /^(receber notificação|notify me|ativar lembrete|remind me|recordarme|notificarme)$/i; const DOT_RE = /^\s*[•·]\s*$/; const seen = new WeakMap(); const hideEl = (el) => el && el.style.setProperty('display', 'none', 'important'); const hideViews = () => { document.querySelectorAll(CARDS).forEach((card) => { const sig = card.textContent.length; if (seen.get(card) === sig) return; seen.set(card, sig); // 1) view count: the outermost element whose whole text is just the count card.querySelectorAll('span, div, yt-formatted-string').forEach((el) => { if (el.closest('#video-title, h3, [class*="__title"]')) return; const text = el.textContent.replace(/ /g, ' ').trim(); if (!text || !VIEWS_RE.test(text)) return; const parentText = el.parentElement?.textContent.replace(/ /g, ' ').trim(); if (parentText && VIEWS_RE.test(parentText)) return; // parent will handle it hideEl(el); // icon before it (no text) and the "•" separator next to it const prev = el.previousElementSibling; if (prev && !prev.textContent.trim()) hideEl(prev); for (const sib of [el.previousSibling, el.nextSibling, el.previousElementSibling, el.nextElementSibling]) { if (!sib) continue; if (sib.nodeType === 3 && DOT_RE.test(sib.textContent)) { sib.textContent = ''; break; } if (sib.nodeType === 1 && (DOT_RE.test(sib.textContent) || /delimiter|separator/.test(sib.className))) { hideEl(sib); break; } } }); // 2) "Receber notificação" button on premieres card.querySelectorAll('button, a').forEach((b) => { if (!NOTIFY_RE.test(b.textContent.trim())) return; hideEl(b.closest('ytd-toggle-button-renderer, ytd-button-renderer, yt-button-view-model, button-view-model, #buttons') || b); }); }); }; observe(hideViews); } if (IS_YT && S.yt_relatedWidth) { const w = S.yt_relatedWidth; css.push(` ytd-watch-flexy { --ytd-watch-flexy-sidebar-width: ${w}px !important; --ytd-watch-flexy-sidebar-min-width: ${w}px !important; } ytd-watch-flexy:not([theater]):not([fullscreen]) #secondary.ytd-watch-flexy { width: ${w}px !important; min-width: ${w}px !important; max-width: ${w}px !important; } `); } if (IS_YT && S.yt_shortcuts) { const ICONS = { history: 'M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.95 8.95 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z', playlists: 'M3 10h11v2H3zm0-4h11v2H3zm0 8h7v2H3zm13-1v8l6-4z', later: 'M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z', liked: 'M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2z', }; ICONS.home = 'M4 21V10.08l8-6.96 8 6.96V21h-6v-6h-4v6H4z'; ICONS.subs = 'M20 8H4V6h16v2zm-2-6H6v2h12V2zm4 10v8c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2v-8c0-1.1.9-2 2-2h16c1.1 0 2 .9 2 2zm-6 4-6-3.27v6.53L16 16z'; // [label, href, icon] — icon null = section header const LINKS = [ ['Home', '/', ICONS.home], ['Subscriptions', '/feed/subscriptions', ICONS.subs], 'sep', ['You', '/feed/you', 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zm0 2c-4.42 0-8 2.24-8 5v1h16v-1c0-2.76-3.58-5-8-5zm0-8a2 2 0 1 1 0 4 2 2 0 0 1 0-4zm0 10c2.97 0 5.4 1.24 5.92 2H6.08c.52-.76 2.95-2 5.92-2z'], ['History', '/feed/history', ICONS.history], ['Liked', '/playlist?list=LL', ICONS.liked], ['Watch later', '/playlist?list=WL', ICONS.later], ['Playlists', '/feed/playlists', ICONS.playlists], ]; css.push(` /* Only our links in the sidebar */ ytd-guide-renderer #sections > :not(#mn-shortcuts), ytd-guide-renderer #footer { display: none !important; } ytd-mini-guide-entry-renderer:not([aria-label="Início"]):not([aria-label="Home"]):not([aria-label="Inscrições"]):not([aria-label="Subscriptions"]):not([aria-label="Você"]):not([aria-label="You"]) { display: none !important; } #mn-shortcuts { padding: 12px; } #mn-shortcuts a { display: flex; align-items: center; gap: 24px; height: 40px; padding: 0 12px; border-radius: 10px; color: #0f0f0f !important; text-decoration: none; font: 400 14px/20px Roboto, Arial, sans-serif; transition: background-color .1s; } html[dark] #mn-shortcuts a { color: #f1f1f1 !important; } #mn-shortcuts a:hover { background: rgba(0, 0, 0, .05); } #mn-shortcuts a:active { background: rgba(0, 0, 0, .1); } #mn-shortcuts a.mn-active { background: rgba(0, 0, 0, .05); font-weight: 500; } html[dark] #mn-shortcuts a:hover { background: rgba(255, 255, 255, .1); } html[dark] #mn-shortcuts a:active { background: rgba(255, 255, 255, .2); } html[dark] #mn-shortcuts a.mn-active { background: rgba(255, 255, 255, .1); } #mn-shortcuts a.mn-header { font-size: 16px; font-weight: 700; } #mn-shortcuts hr { border: 0; border-top: 1px solid rgba(0, 0, 0, .1); margin: 12px 0; } html[dark] #mn-shortcuts hr { border-top-color: rgba(255, 255, 255, .2); } #mn-shortcuts svg { display: block !important; width: 24px !important; height: 24px !important; min-width: 24px !important; flex: none !important; color: inherit !important; } #mn-shortcuts svg path { fill: currentColor !important; } `); const NS = 'http://www.w3.org/2000/svg'; const build = () => { const box = document.createElement('div'); box.id = 'mn-shortcuts'; for (const item of LINKS) { if (item === 'sep') { box.appendChild(document.createElement('hr')); continue; } const [label, href, path] = item; const a = document.createElement('a'); a.href = href; a.dataset.href = href; if (path) { const svg = document.createElementNS(NS, 'svg'); svg.setAttribute('viewBox', '0 0 24 24'); const p = document.createElementNS(NS, 'path'); p.setAttribute('d', path); svg.appendChild(p); a.appendChild(svg); } else { a.className = 'mn-header'; } const span = document.createElement('span'); span.textContent = label; a.appendChild(span); box.appendChild(a); } return box; }; const placeShortcuts = () => { const sections = document.querySelector('ytd-guide-renderer #sections'); if (!sections) return; let box = document.getElementById('mn-shortcuts'); if (!box) { box = build(); sections.prepend(box); } // Use the same text colour as YouTube's own sidebar items const ref = document.querySelector('ytd-guide-entry-renderer:not([hidden]) .title, ytd-guide-entry-renderer yt-formatted-string'); const c = ref && getComputedStyle(ref).color; if (c && box.dataset.color !== c) { box.dataset.color = c; box.querySelectorAll('a').forEach((a) => a.style.setProperty('color', c, 'important')); } const here = location.pathname + location.search; box.querySelectorAll('a').forEach((a) => { const h = a.dataset.href; const on = h === '/' ? location.pathname === '/' : here.startsWith(h); a.classList.toggle('mn-active', on && !a.classList.contains('mn-header')); }); }; observe(placeShortcuts); window.addEventListener('yt-navigate-finish', placeShortcuts); } // ============================================ LIVE MODE (subscriptions split) // Live button = Subscriptions showing only live streams. // Normal Subscriptions = everything except live streams. const SUBS = '/feed/subscriptions'; let liveMode = location.pathname === SUBS && location.hash === '#live'; let pendingLive = null; const LIVE_ON = IS_YT && S.yt_topnav && S.yt_livebtn; function applyLiveMode() { document.documentElement.classList.toggle('mn-live-mode', liveMode && location.pathname === SUBS); document.getElementById('mn-topnav')?.dispatchEvent(new Event('mn-refresh')); } if (LIVE_ON) { const P = 'ytd-browse[page-subtype="subscriptions"] ytd-rich-item-renderer'; css.push(` html.mn-live-mode ${P}:not(.mn-is-live), html:not(.mn-live-mode) ${P}.mn-is-live { display: none !important; } /* In Live view, stop the endless "load more" (grey placeholder cards + spinner) */ html.mn-live-mode ytd-browse[page-subtype="subscriptions"] ytd-continuation-item-renderer, html.mn-live-mode ytd-browse[page-subtype="subscriptions"] ytd-ghost-grid-renderer, html.mn-live-mode ytd-browse[page-subtype="subscriptions"] #ghost-cards, html.mn-live-mode ytd-browse[page-subtype="subscriptions"] [class*="ghost"], html.mn-live-mode ytd-browse[page-subtype="subscriptions"] tp-yt-paper-spinner { display: none !important; } #mn-nolive { display: none; margin: 48px auto; text-align: center; opacity: .7; font: 500 16px/24px Roboto, Arial, sans-serif; color: #f1f1f1; } html:not([dark]) #mn-nolive { color: #0f0f0f; } html.mn-live-mode.mn-live-empty #mn-nolive { display: block; } `); const LIVE_RE = /^(ao vivo|live|live now|en vivo|en direct)$/i; const BADGES = 'badge-shape, ytd-badge-supported-renderer, ytd-thumbnail-overlay-time-status-renderer, [class*="badge"]'; const markLive = () => { if (location.pathname !== SUBS) return; document.querySelectorAll(P).forEach((item) => { const live = !!item.querySelector('[overlay-style="LIVE"], .badge-style-type-live-now, .badge-style-type-live-now-alternate, [aria-label="AO VIVO"], [aria-label="LIVE"]') || [...item.querySelectorAll(BADGES)].some((b) => LIVE_RE.test(b.textContent.trim())); item.classList.toggle('mn-is-live', live); }); // "Nobody is live" message when there's nothing to show const grid = document.querySelector('ytd-browse[page-subtype="subscriptions"] ytd-rich-grid-renderer'); if (grid && !document.getElementById('mn-nolive')) { const msg = document.createElement('div'); msg.id = 'mn-nolive'; msg.textContent = 'Nobody you follow is live right now'; grid.parentNode.insertBefore(msg, grid); } const loaded = document.querySelectorAll(P).length > 0; const anyLive = !!document.querySelector(`${P}.mn-is-live`); document.documentElement.classList.toggle('mn-live-empty', loaded && !anyLive); }; observe(markLive); window.addEventListener('yt-navigate-finish', () => { if (pendingLive !== null) { liveMode = pendingLive; pendingLive = null; } else if (location.pathname !== SUBS) liveMode = false; applyLiveMode(); }); applyLiveMode(); } // ============================================ TOP BAR HOME / SUBSCRIPTIONS if (IS_YT && S.yt_topnav) { const NAV = [ ['Home', '/', 'M4 21V10.08l8-6.96 8 6.96V21h-6v-6h-4v6H4z', 'home'], ['Subscriptions', SUBS, 'M20 8H4V6h16v2zm-2-6H6v2h12V2zm4 10v8c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2v-8c0-1.1.9-2 2-2h16c1.1 0 2 .9 2 2zm-6 4-6-3.27v6.53L16 16z', 'subs'], ]; if (LIVE_ON) { NAV.push(['Live', SUBS + '#live', 'M7.76 16.24C6.67 15.16 6 13.66 6 12s.67-3.16 1.76-4.24l1.42 1.42C8.45 9.9 8 10.9 8 12s.45 2.1 1.17 2.83l-1.41 1.41zm8.48 0C17.33 15.16 18 13.66 18 12s-.67-3.16-1.76-4.24l-1.42 1.42C15.55 9.9 16 10.9 16 12s-.45 2.1-1.17 2.83l1.41 1.41zM12 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm8 2c0 2.21-.9 4.21-2.35 5.65l1.42 1.42C20.88 17.26 22 14.76 22 12s-1.12-5.26-2.93-7.07l-1.42 1.42C19.1 7.79 20 9.79 20 12zM6.35 6.35 4.93 4.93C3.12 6.74 2 9.24 2 12s1.12 5.26 2.93 7.07l1.42-1.42C4.9 16.21 4 14.21 4 12s.9-4.21 2.35-5.65z', 'live']); } css.push(` #mn-topnav { display: flex !important; align-items: center; gap: 8px; margin: 0 8px 0 0 !important; flex: none !important; visibility: visible !important; opacity: 1 !important; } /* YouTube leaves a big left margin on the search box — remove it so the gap is even */ #mn-topnav + yt-searchbox, #mn-topnav + ytd-searchbox, #mn-topnav + #search-form { margin-left: 0 !important; } #mn-topnav a { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .05); color: #0f0f0f !important; transition: background-color .15s, transform .15s; } #mn-topnav a:hover { background: rgba(0, 0, 0, .1); } #mn-topnav a:active { transform: scale(.94); } #mn-topnav a.mn-active { background: rgba(0, 0, 0, .15); } html[dark] #mn-topnav a { background: rgba(255, 255, 255, .1); color: #f1f1f1 !important; } html[dark] #mn-topnav a:hover { background: rgba(255, 255, 255, .2); } html[dark] #mn-topnav a.mn-active { background: rgba(255, 255, 255, .25); } #mn-topnav a.mn-live.mn-active { background: #cc0000 !important; color: #fff !important; } #mn-topnav svg { width: 22px; height: 22px; display: block; } #mn-topnav svg path { fill: currentColor; } `); const NS = 'http://www.w3.org/2000/svg'; const placeTopNav = () => { const search = document.querySelector('#masthead yt-searchbox, #masthead ytd-searchbox, ytd-masthead yt-searchbox, ytd-masthead ytd-searchbox') || document.querySelector('yt-searchbox, ytd-searchbox, #search-form'); const start = document.querySelector('ytd-masthead #start, #masthead #start'); if (!search && !start) return; let box = document.getElementById('mn-topnav'); if (!box) { box = document.createElement('div'); box.id = 'mn-topnav'; box.addEventListener('mn-refresh', () => placeTopNav()); for (const [label, href, path, key] of NAV) { const a = document.createElement('a'); a.href = href; a.dataset.href = href; a.dataset.key = key; if (key === 'live') a.classList.add('mn-live'); a.title = label; a.setAttribute('aria-label', label); const svg = document.createElementNS(NS, 'svg'); svg.setAttribute('viewBox', '0 0 24 24'); const p = document.createElementNS(NS, 'path'); p.setAttribute('d', path); svg.appendChild(p); a.appendChild(svg); box.appendChild(a); } } // (Re)place it right before the search box; fall back to after the logo if (search && search.parentNode) { if (box.nextElementSibling !== search) search.parentNode.insertBefore(box, search); } else if (start && box.parentNode !== start) { start.appendChild(box); } const onSubs = location.pathname === SUBS; box.querySelectorAll('a').forEach((a) => { const k = a.dataset.key; const on = k === 'home' ? location.pathname === '/' : k === 'subs' ? onSubs && !(LIVE_ON && liveMode) : onSubs && liveMode; a.classList.toggle('mn-active', on); }); }; observe(placeTopNav); window.addEventListener('yt-navigate-finish', placeTopNav); } // Open our links without reloading the page, by clicking YouTube's own (hidden) link if (IS_YT) { document.addEventListener('click', (e) => { const a = e.target.closest?.('#mn-topnav a, #mn-shortcuts a'); if (!a || e.ctrlKey || e.metaKey || e.shiftKey || e.button !== 0) return; let href = a.dataset.href; // Live / Subscriptions share the same page, only the filter changes if (LIVE_ON && href.startsWith(SUBS)) { const wantLive = a.dataset.key === 'live'; href = SUBS; if (location.pathname === SUBS) { e.preventDefault(); liveMode = wantLive; applyLiveMode(); window.scrollTo({ top: 0 }); return; } pendingLive = wantLive; } const native = document.querySelector( `ytd-guide-entry-renderer a[href="${href}"], ytd-mini-guide-entry-renderer a[href="${href}"]` ); if (native) { e.preventDefault(); native.click(); } }, true); } // ======================================================================= X if (IS_X) { if (S.x_trends) { hide([ '[data-testid="sidebarColumn"] section:has([data-testid="trend"])', '[data-testid="sidebarColumn"] div:has(> section [data-testid="trend"])', ]); } if (S.x_wtf) { hide([ '[data-testid="sidebarColumn"] aside:has([data-testid="UserCell"])', '[data-testid="sidebarColumn"] div:has(> aside [data-testid="UserCell"])', ]); } const AD_WORDS = new Set(['Ad', 'Promoted', 'Anúncio', 'Promovido', 'Anuncio', 'Publicidad']); const REPLY_RE = /^(Replying to|Respondendo a|En respuesta a)\b/; const isAd = (article) => [...article.querySelectorAll('span')].some( (s) => !s.closest('[data-testid="tweetText"]') && AD_WORDS.has(s.textContent.trim()) ); const isRepost = (article) => !!article.querySelector('[data-testid="socialContext"]')?.closest('a'); const isReply = (article) => [...article.querySelectorAll('div')].some( (d) => !d.closest('[data-testid="tweetText"]') && d.children.length <= 2 && REPLY_RE.test(d.textContent.trim()) ); const cleanX = () => { const onHome = location.pathname === '/home'; // "For You" tab -> switch to "Following" and hide the tab if (S.x_foryou && onHome) { const tabs = document.querySelectorAll('[data-testid="primaryColumn"] [role="tablist"] [role="tab"]'); if (tabs.length > 1) { if (tabs[0].getAttribute('aria-selected') === 'true') tabs[1].click(); const wrap = tabs[0].closest('[role="presentation"]') || tabs[0]; wrap.style.setProperty('display', 'none', 'important'); } } // Timeline filters document.querySelectorAll('[data-testid="primaryColumn"] [data-testid="cellInnerDiv"]').forEach((cell) => { const article = cell.querySelector('article'); let kill = false; if (article) { if (S.x_ads && isAd(article)) kill = true; else if (S.x_reposts && isRepost(article)) kill = true; else if (S.x_replies && onHome && isReply(article)) kill = true; } else if (S.x_wtf && onHome && cell.querySelector('[data-testid="UserCell"]')) { kill = true; // "Who to follow" block inside the home timeline } cell.style.display = kill ? 'none' : ''; }); }; observe(cleanX); } // ------------------------------------------------------------ apply styles if (css.length) GM_addStyle(css.join('\n')); })();