GitHub Gist Link

Adds a Gist link to GitHub profile pages.

2025-02-26 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GitHub Gist Link
// @description  Adds a Gist link to GitHub profile pages.
// @icon         https://github.githubassets.com/favicons/favicon-dark.svg
// @version      1.0
// @author       afkarxyz
// @namespace    https://github.com/afkarxyz/misc-scripts/
// @supportURL   https://github.com/afkarxyz/misc-scripts/issues
// @license      MIT
// @match        https://github.com/*
// @exclude      https://gist.github.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';
    
    function isProfilePage() {
        return /^\/[^\/]+\/?$/.test(window.location.pathname);
    }
    
    function addGistLink() {
        if (!isProfilePage()) return;
        
        const usernameElement = document.querySelector('.p-nickname.vcard-username');
        
        if (usernameElement && !usernameElement.querySelector('.gist-link-userscript')) {
            const currentURL = window.location.pathname;
            const username = currentURL.split('/')[1];
            
            const linkContainer = document.createElement('span');
            linkContainer.className = 'gist-link-container';
            
            const gistLink = document.createElement('a');
            gistLink.href = `https://gist.github.com/${username}`;
            gistLink.textContent = 'Gist';
            gistLink.className = 'Link--secondary gist-link-userscript';
            gistLink.style.textDecoration = 'none';
            
            linkContainer.appendChild(gistLink);
            linkContainer.appendChild(document.createTextNode(' · '));
            
            usernameElement.insertBefore(linkContainer, usernameElement.firstChild);
        }
    }
    
    function observeForUsernameElement() {
        if (!isProfilePage()) return;
        
        const usernameObserver = new MutationObserver((mutations, observer) => {
            const usernameElement = document.querySelector('.p-nickname.vcard-username');
            if (usernameElement) {
                addGistLink();
                observer.disconnect();
            }
        });
        
        usernameObserver.observe(document.body, { 
            childList: true, 
            subtree: true 
        });
    }
    
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        addGistLink();
    } else {
        document.addEventListener('DOMContentLoaded', addGistLink);
    }
    
    let lastUrl = location.href;
    const urlChangeObserver = new MutationObserver(() => {
        const url = location.href;
        if (url !== lastUrl) {
            lastUrl = url;
            if (document.querySelector('.p-nickname.vcard-username')) {
                addGistLink();
            } else {
                observeForUsernameElement();
            }
        }
    });
    
    urlChangeObserver.observe(document, {
        subtree: true, 
        childList: true
    });
    
    window.addEventListener('popstate', function() {
        if (document.querySelector('.p-nickname.vcard-username')) {
            addGistLink();
        } else {
            observeForUsernameElement();
        }
    });
    
    observeForUsernameElement();
})();