Github Commit Whitespace

Adds button to hide whitespaces from commit

2016-08-02 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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 Commit Whitespace
// @namespace   https://github.com/jerone/UserScripts
// @description Adds button to hide whitespaces from commit
// @author      jerone
// @copyright   2014+, jerone (http://jeroenvanwarmerdam.nl)
// @license     GNU GPLv3
// @homepage    https://github.com/jerone/UserScripts/tree/master/Github_Commit_Whitespace
// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Commit_Whitespace
// @supportURL  https://github.com/jerone/UserScripts/issues
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
// @icon        https://github.com/fluidicon.png
// @include     https://github.com/*
// @version     1.4.4
// @grant       none
// ==/UserScript==
/* global unsafeWindow */

(function() {

    function addButton() {
        var e;
        if ((/\/commit\//.test(location.href) || /\/compare\//.test(location.href)) && (e = document.getElementById("toc"))) {

            var r = e.querySelector(".GithubCommitWhitespaceButton");
            if (r) {
                r.parentElement.removeChild(r);
            }

            var on = /w=/.test(location.search); // any occurense results in enabling;

            var b = e.querySelector(".toc-diff-stats");

            var a = document.createElement("a");
            a.classList.add("btn", "btn-sm", "tooltipped", "tooltipped-n");
            if (on) {
                a.classList.add("selected");
            }
            a.setAttribute("href", url(on));
            a.setAttribute("rel", "nofollow");
            a.setAttribute("aria-label", on ? "Show commit whitespace" : "Hide commit whitespace");
            a.appendChild(document.createTextNode(" \u2423"));

            var g = document.createElement("div");
            g.classList.add("GithubCommitWhitespaceButton", "right");
            g.style.margin = "0 10px 0 0"; // give us some room;
            g.appendChild(a);

            b.parentNode.insertBefore(g, b);
        } else if (/\/pull\/\d*\/files/.test(location.href) && (e = document.querySelector("#files_bucket .pr-toolbar .diffbar > .float-right"))) {

            var r = e.querySelector(".GithubCommitWhitespaceButton");
            if (r) {
                r.parentElement.removeChild(r);
            }

            var on = /w=/.test(location.search); // any occurense results in enabling;

            var a = document.createElement("a");
            a.classList.add("btn-link", "muted-link");
            a.setAttribute("href", url(on));
            a.setAttribute("rel", "nofollow");
            a.setAttribute("aria-label", on ? "Show commit whitespace" : "Hide commit whitespace");
            a.appendChild(document.createTextNode(on ? "Show whitespace" : "Hide whitespace"));

            var g = document.createElement("div");
            g.classList.add("GithubCommitWhitespaceButton", "diffbar-item");
            g.appendChild(a);

            e.insertBefore(g, e.firstChild);
        }
    }

    function url(on) {
        var searches = location.search.replace(/^\?/, "").split("&").filter(function(item) {
            return item && !/w=.*/.test(item);
        });
        if (!on) {
            searches.push("w=1");
        }
        return location.href.replace(location.search, "") + (searches.length > 0 ? "?" + searches.join("&") : "");
    }

    // init;
    addButton();

    // on pjax;
    document.addEventListener('pjax:end', addButton);

})();