Github Commit Diff

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

27.02.2014 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        Github Commit Diff
// @namespace   https://greasyfork.org/scripts/77
// @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
// @downloadURL https://greasyfork.org/scripts/77/code.user.js
// @include     http*://github.com/*
// @version     1.20140227141649
// @grant       none
// @updateURL https://greasyfork.org/scripts/77/code.meta.js
// ==/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);

})();