Hide video recommendations from listing and remove annoying auto-mix playlists to reduce lag and improve performance
目前為
// ==UserScript==
// @name LiteTube
// @namespace http://tampermonkey.net/
// @version v1.2
// @description Hide video recommendations from listing and remove annoying auto-mix playlists to reduce lag and improve performance
// @author Liminality Dreams
// @match https://www.youtube.com/*
// @icon https://img.icons8.com/?size=100&id=62852&format=png&color=228BE6
// @grant none
// @run-at document-start
// @license GNU 3.0
// ==/UserScript==
(function() {
'use strict';
let hasReloaded = false;
function isAutoMix(listId) {
if (!listId) return false;
return listId.startsWith('RD') && !listId.startsWith('RDMM') && !listId.startsWith('RDAO') && !listId.startsWith('RDCLAK') && !listId.startsWith('RDTM') && !listId.startsWith('RDEM') && !listId.startsWith('RDPN');
}
function isWatchPage() {
return window.location.pathname === '/watch';
}
function checkAndReload() {
if (!isWatchPage() || hasReloaded) return;
const url = new URL(window.location.href);
const listParam = url.searchParams.get('list');
if (listParam && isAutoMix(listParam)) {
hasReloaded = true;
url.searchParams.delete('list');
url.searchParams.delete('start_radio');
url.searchParams.delete('index');
window.location.replace(url.toString());
}
}
function removeWatchPageSidebar() {
if (!isWatchPage()) return;
document.querySelectorAll('#secondary').forEach(el => el.remove());
document.querySelectorAll('ytd-watch-next-secondary-results-renderer').forEach(el => el.remove());
}
function removeBloat() {
const bloatSelectors = [
'ytd-rich-shelf-renderer[is-gaming]',
'ytd-statement-banner-renderer',
'ytd-banner-promo-renderer',
'ytd-compact-promoted-video-renderer',
'ytd-display-ad-renderer',
'ytd-promoted-sparkles-web-renderer'
];
bloatSelectors.forEach(selector => {
document.querySelectorAll(selector).forEach(el => el.remove());
});
}
const style = document.createElement('style');
style.textContent = `
body[is-watch-page] #secondary,
body[is-watch-page] ytd-watch-next-secondary-results-renderer,
ytd-playlist-panel-renderer,
.ytp-playlist-menu {
display: none !important;
}
`;
document.head.appendChild(style);
checkAndReload();
const observer = new MutationObserver(() => {
if (isWatchPage()) {
removeWatchPageSidebar();
}
removeBloat();
});
const startObserver = () => {
if (document.body) {
observer.observe(document.body, {
subtree: true,
childList: true
});
}
};
if (document.body) {
startObserver();
} else {
document.addEventListener('DOMContentLoaded', startObserver);
}
window.addEventListener('yt-navigate-finish', () => {
hasReloaded = false;
checkAndReload();
if (isWatchPage()) {
setTimeout(removeWatchPageSidebar, 100);
}
});
})();