YouTube Branding Image Remover

Removes branding images (elements with class 'branding-img') from YouTube pages to provide a cleaner interface.

目前為 2025-05-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube Branding Image Remover
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Removes branding images (elements with class 'branding-img') from YouTube pages to provide a cleaner interface.
// @author       Your Name/AI
// @match        *://*.youtube.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function removeBrandingImages() {
        const images = document.querySelectorAll('img.branding-img');
        let imagesRemovedThisRun = 0;

        images.forEach(img => {
            if (document.body.contains(img)) {
                img.remove();
                imagesRemovedThisRun++;
            }
        });

        if (imagesRemovedThisRun > 0) {
            // console.log(`[YouTube Branding Image Remover] Removed ${imagesRemovedThisRun} branding image(s).`);
        }
    }

    // Initial run
    removeBrandingImages();

    // Observe DOM changes for dynamically loaded content
    const observer = new MutationObserver(function(mutationsList, observerInstance) {
        let potentiallyNewBrandingImages = false;
        for(const mutation of mutationsList) {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                for (const node of mutation.addedNodes) {
                    if (node.nodeType === 1) { 
                        if (node.matches && node.matches('img.branding-img')) {
                            potentiallyNewBrandingImages = true;
                            break;
                        }
                        if (node.querySelector && node.querySelector('img.branding-img')) {
                            potentiallyNewBrandingImages = true;
                            break;
                        }
                    }
                }
            }
            if (potentiallyNewBrandingImages) break;
        }

        if (potentiallyNewBrandingImages) {
            removeBrandingImages();
        }
    });

    function startObserver() {
        if (document.body) {
            observer.observe(document.body, { childList: true, subtree: true });
        } else {
            document.addEventListener('DOMContentLoaded', function() {
                observer.observe(document.body, { childList: true, subtree: true });
            });
        }
    }

    startObserver();

})();