GitHub Animated Profile Picture

Replace GitHub profile picture with a custom image from the user's repository if the image exists

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         GitHub Animated Profile Picture
// @namespace    https://github.com/PatoFlamejanteTV
// @version      1.40
// @description  Replace GitHub profile picture with a custom image from the user's repository if the image exists
// @author       PatoFlamejanteTV
// @license MIT
// @match        *://github.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function checkImage(url) {
        return new Promise((resolve) => {
            const img = new Image();
            img.onload = () => resolve(true);
            img.onerror = () => resolve(false);
            img.src = url;
        });
    }

    const profilePictureClasses = [
        'avatar mr-2 d-none d-md-block avatar-user',
        'avatar avatar-user width-full border color-bg-default',
        'avatar circle',
    ];

    const username = window.location.pathname.split('/').filter(Boolean)[0];
    const customImageUrl = `https://raw.githubusercontent.com/${username}/${username}/refs/heads/main/anim_pfp/pfp.gif`;

    console.log("Checking Image:", customImageUrl);

    function attemptProfilePictureChange(attempts) {
        checkImage(customImageUrl).then(exists => {
            if (exists) {
                profilePictureClasses.forEach(profileClass => {
                    const profilePictures = document.getElementsByClassName(profileClass);
                    Array.from(profilePictures).forEach(img => {
                        img.src = customImageUrl;
                        img.srcset = customImageUrl;
                    });
                });
            } else if (attempts > 0) {
                console.log(`Attempt failed. Retrying... (${attempts} attempts left)`);
                setTimeout(() => attemptProfilePictureChange(attempts - 1), 2000);
            } else {
                console.log("Animated PFP not found after multiple attempts.");
            }
        });
    }

    attemptProfilePictureChange(3); // Start with 3 attempts
})();