Select Git revision
script.js 2.92 KiB
// ==UserScript==
// @name Remove Youtube Propaganda
// @namespace https://github.com/Dwyriel
// @version 1.5.1
// @description Tries to remove any banner and other dismissibles that are plain annoying (or straight up propaganda).
// @author Dwyriel
// @license MIT
// @match *://*.youtube.com/*
// @grant none
// @homepageURL https://github.com/Dwyriel/Greasyfork-Scripts
// ==/UserScript==
(function () {
'use strict';
const userscriptName = "[Remove Youtube Propaganda]";
const idsToRemove = [
"big-yoodle", //main page banner
"clarify-box" //video page "clarification"
];
const elementsToRemove = [
"ytm-statement-banner-renderer", "ytd-statement-banner-renderer", //main page banner
"ytm-clarification-renderer", "ytd-clarification-renderer", //search page "clarification" (specific topics only)
"ytm-info-panel-container-renderer", "ytd-info-panel-container-renderer", //search page "clarification" (specific topics only)
"ytm-brand-video-singleton-renderer", "ytd-brand-video-singleton-renderer", //a very specific video youtube is promoting in the main page (for reasons)
"yt-mealbar-promo-renderer" //youtube premium/ad-free popup, afaik there's no mobile version
];
const elementsByClassToRemove = [];
const replaceYoutubeLogo = () => {
//context: usually returns an array with two elements, second one was always hidden, no idea what it's used for.
const firstYoutubeLogo = document.getElementsByTagName("ytd-yoodle-renderer")[0];
let isEventLogoActive = firstYoutubeLogo.getAttribute("hidden") === null;
if (!isEventLogoActive)
return;
firstYoutubeLogo.parentElement.getElementsByTagName("div")[0].removeAttribute("hidden");
firstYoutubeLogo.setAttribute("hidden", "");
};
const callback = () => {
for (let id of idsToRemove) {
let element = document.getElementById(id);
if (element) {
element.remove();
console.log(`${userscriptName} Removed element of id: ${id}`);
}
}
for (let elementName of elementsToRemove) {
let elements = document.getElementsByTagName(elementName);
for (let element of elements) {
element.remove();
console.log(`${userscriptName} Removed element with tag name: ${elementName}`);
}
}
for (let className of elementsByClassToRemove) {
let elements = document.getElementsByClassName(className);
for (let element of elements) {
element.remove();
console.log(`${userscriptName} Removed element with class: ${elementName}`);
}
}
replaceYoutubeLogo();
};
const config = { attributes: true, childList: true, subtree: true };
new MutationObserver(callback).observe(document.body, config);
})();