GitHub File History

GitHub File History (Open in github.githistory.xyz)

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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 File History
// @namespace    https://blog.xlab.app/
// @supportURL   https://github.com/ttttmr/UserJS
// @version      0.8
// @description  GitHub File History (Open in github.githistory.xyz)
// @author       tmr
// @match        https://github.com/*/*
// @grant        none
// ==/UserScript==

(function () {
  "use strict";

  function injectButton() {
    // Only show on file pages (GitHub uses /blob/ for files)
    if (!window.location.pathname.includes('/blob/')) return;

    if (document.getElementById('gh-file-history-btn')) return;

    // Find the native history button
    const historyIcon = document.querySelector("svg.octicon-history");
    if (!historyIcon) return;

    const nativeBtn = historyIcon.closest('a');
    if (!nativeBtn) return;

    // The nativeBtn is usually inside a list item or a div group
    const container = nativeBtn.parentElement;
    if (!container) return;

    // Create our button by cloning the native one to keep the style
    const githistoryBtn = nativeBtn.cloneNode(true);
    githistoryBtn.id = 'gh-file-history-btn';
    
    // Distinguish it: Add a lightning emoji
    const textNode = Array.from(githistoryBtn.childNodes).find(n => n.nodeType === Node.TEXT_NODE || n.tagName === 'SPAN');
    if (textNode) {
        if (textNode.tagName === 'SPAN') {
            textNode.textContent = ' ⚡️';
        } else {
            textNode.textContent = ' ⚡️';
        }
    } else {
        // Fallback
        githistoryBtn.appendChild(document.createTextNode(' ⚡️'));
    }

    // Update URL
    githistoryBtn.href = githistoryBtn.href.replace("github.com", "github.githistory.xyz");
    
    // Style hint
    githistoryBtn.title = 'Open in GitHistory'; // Add tooltip since text is gone

    // Insert next to the native button
    container.parentNode.insertBefore(githistoryBtn, container.nextSibling);
  }

  // Run and observe for SPA navigation
  injectButton();
  
  const observer = new MutationObserver(() => {
    injectButton();
  });
  
  observer.observe(document.body, {
    childList: true,
    subtree: true
  });
})();