🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Github Commit Diff

Adds button to show diff (or patch) file for commit

当前为 2014-02-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name        Github Commit Diff
// @namespace   https://github.com/jerone/UserScripts
// @description Adds button to show diff (or patch) file for commit
// @author      jerone
// @homepage    https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
// @include     http*://github.com/*
// @version     1
// @grant       none
// ==/UserScript==


(function(){

    function addButton() {
        if(!/\/commit\//.test(location.href) || !document.querySelector(".explain")) return;
        
        var r;
        if((r = document.querySelector(".GithubCommitDiffButton"))) r.parentElement.removeChild(r);
        
        function getPatchOrDiffHref(type){
            return (document.querySelector("link[type='text/plain+" + type + "']") 
               || { href: location.href + "." + type }).href;
        };
        
        var b = document.querySelector(".explain .minibutton");
           
        var s = document.createElement("span");
        s.textContent = " ";
        s.classList.add("octicon", "octicon-diff");
        s.style.color = "#333";  // set color because of css selector `p.explain .octicon`;
        
        var a = document.createElement("a");
        a.classList.add("GithubCommitDiffButton", "minibutton", "tooltipped", "tooltipped-s");
        a.setAttribute("href", getPatchOrDiffHref("diff"));
        a.setAttribute("title", "Show commit diff.\r\nHold Shift to open commit patch.");
        a.setAttribute("rel", "nofollow");
        a.setAttribute("aria-label", a.getAttribute("title"));
        a.style.marginLeft = "10px";  // give us some room;
        a.appendChild(s);
        a.appendChild(document.createTextNode("Diff"));
    
        b.parentNode.insertBefore(a, b);
        
        a.addEventListener("click", function(e){
            if(e.shiftKey) {
                e.preventDefault();
                location.href = getPatchOrDiffHref("patch");
            }
        }, false);
    }
    
    // init;
    addButton();
    
    // on pjax;
    $(document).on('pjax:success', addButton);

})();