GitHub Home → Profile

Redirect the GitHub logo: cycle between Home / Profile / Repositories via the Tampermonkey menu

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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 यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GitHub Home → Profile
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Redirect the GitHub logo: cycle between Home / Profile / Repositories via the Tampermonkey menu
// @author       AIPEAC
// @match        https://github.com/*
// @license      Unlicense
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function () {
    'use strict';

    const MODES = [
        { label: '🏠 Home',          href: username => '/' },
        { label: '👤 Profile',       href: username => '/' + username },
        { label: '📁 Repositories',  href: username => '/' + username + '?tab=repositories' },
    ];

    let currentMode = GM_getValue('logoMode', 1); // default: Profile

    function getUsername() {
        return document.querySelector('meta[name="user-login"]')?.content;
    }

    function patchIcon() {
        const username = getUsername();
        if (!username) return;

        const anchor = document.querySelector('a svg.octicon-mark-github')?.closest('a');
        if (!anchor) return;

        anchor.setAttribute('href', MODES[currentMode].href(username));
    }

    function cycleMode() {
        currentMode = (currentMode + 1) % MODES.length;
        GM_setValue('logoMode', currentMode);
        patchIcon();
        updateMenu();
    }

    function updateMenu() {
        const next = MODES[(currentMode + 1) % MODES.length].label;
        GM_registerMenuCommand('GitHub logo → ' + MODES[currentMode].label + '  |  click to switch to: ' + next, cycleMode);
    }

    patchIcon();
    updateMenu();

    // GitHub is a SPA — re-patch after navigation events reset the DOM
    const observer = new MutationObserver(patchIcon);
    observer.observe(document.documentElement, { childList: true, subtree: true });
})();