YouTube Avatars Fix

Fixes the display of avatars on YouTube

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

// ==UserScript==
// @name         YouTube Avatars Fix
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Fixes the display of avatars on YouTube
// @author       frz
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @match        https://*.youtube.com/*
// @match        https://studio.youtube.com/*
// @match        https://yt3.googleusercontent.com/*
// @match        https://yt4.ggpht.com/*
// @match        https://yt4.googleusercontent.com/*
// @match        https://vidiq.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    function fixAvatarUrl(url) {
        if (!url) return url;

        return url.replace(/yt3\.ggpht\.com/g, 'yt4.ggpht.com');
    }


    function fixImage(img) {
        if (!img || !img.src) return;
        const originalSrc = img.src;

        if (originalSrc.includes('yt3.ggpht.com')) {
            const newSrc = fixAvatarUrl(originalSrc);
            if (newSrc !== originalSrc) {
                img.src = newSrc;

            }
        }
    }


    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {

            if (mutation.addedNodes.length) {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE) {

                        if (node.tagName === 'IMG') {
                            fixImage(node);
                        }

                        if (node.querySelectorAll) {
                            node.querySelectorAll('img[src*="yt3.ggpht.com"]').forEach(fixImage);
                        }
                    }
                });
            }

            if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
                const target = mutation.target;
                if (target.tagName === 'IMG') {
                    fixImage(target);
                }
            }
        });
    });


    observer.observe(document.documentElement, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['src']
    });


    document.querySelectorAll('img[src*="yt3.ggpht.com"]').forEach(fixImage);
})();