GitHub File History

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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
  });
})();