tm-yt-shorts-remover/yt-shorts-remover.js

36 lines
1.2 KiB
JavaScript

// ==UserScript==
// @name YouTube Shorts Blocker & Redirector
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Entfernt Shorts von YouTube + Weiterleitung von /shorts/* zur Startseite
// @author Sven Heidemann
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 1. Weiterleitung, falls URL mit /shorts/ beginnt
if (location.pathname.startsWith('/shorts/')) {
window.location.replace('https://www.youtube.com/');
return;
}
// 2. Funktion zum Entfernen von Shorts-Elementen
function removeShorts() {
// Entferne alle <a title="Shorts">
document.querySelectorAll('a[title="Shorts"]').forEach(el => el.remove());
// Entferne alle Elemente mit dem Attribut is-shorts
document.querySelectorAll('[is-shorts]').forEach(el => el.remove());
}
// 3. Beim Laden ausführen
window.addEventListener('load', removeShorts);
// 4. Auch auf dynamischen Content achten
const observer = new MutationObserver(removeShorts);
observer.observe(document.body, { childList: true, subtree: true });
})();