Consistent Youtube logo

Replace the YouTube logo with a custom image, set a constant width of 94px, update the logo link to youtube.com, and change the mouse-over text to "YouTube".

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Consistent Youtube logo
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Replace the YouTube logo with a custom image, set a constant width of 94px, update the logo link to youtube.com, and change the mouse-over text to "YouTube".
// @author       jflo
// @match        https://www.youtube.com/*
// @grant        none
// @licensec     MIT
// ==/UserScript==

(function() {
    'use strict';

    // URL of the custom logo you want to use
    const customLogoUrl = 'https://i.imgur.com/maYoqkV.png'; // Replace with your custom logo URL
    const customLogoWidth = '94px'; // Set the desired width for the custom logo

    // Function to replace the logo, update the link, and change the mouse-over text
    function replaceLogo() {
        // Select all possible logo image elements
        const logoImages = document.querySelectorAll('img[src*="youtube/img/promos/growth/"]');
        const logoLinks = document.querySelectorAll('a[href*="/?bp=wgUCEAE%3D"]'); // Selector for the logo link

        logoImages.forEach(logoImage => {
            // Replace the logo's src and srcset with the custom logo URL
            logoImage.src = customLogoUrl;
            logoImage.srcset = customLogoUrl;
            // Set the custom width and height
            logoImage.style.width = customLogoWidth;
            logoImage.style.height = 'auto'; // Maintain aspect ratio
            logoImage.width = '94'; // Set width attribute
            logoImage.height = ''; // Clear any height attribute to maintain aspect ratio
            // Set the mouse-over text
            logoImage.alt = 'YouTube';
            logoImage.title = 'YouTube';
        });

        // Update the link associated with the logo
        logoLinks.forEach(logoLink => {
            logoLink.href = 'https://www.youtube.com/';
            logoLink.title = 'YouTube';
        });
    }

    // Run the function when the page loads
    window.addEventListener('load', replaceLogo);

    // Optionally, run the function when the DOM changes (e.g., when navigating within YouTube)
    const observer = new MutationObserver(replaceLogo);
    observer.observe(document.body, { childList: true, subtree: true });
})();