Github Commit Whitespace

Adds button to hide whitespaces from commit

Per 27-01-2018. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==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     GPL-3.0
// @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://assets-cdn.github.com/pinned-octocat.svg
// @include     https://github.com/*
// @version     1.5.3
// @grant       none
// ==/UserScript==

(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', 'float-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|commits)/.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 result in enabling

            var a = document.createElement('a')
            a.classList.add('btn', 'btn-sm', 'btn-outline', 'tooltipped', 'tooltipped-s')
            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', '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, '').replace(location.hash, '') + (searches.length > 0 ? '?' + searches.join('&') : '') + location.hash;
    }

    // Init
    addButton()

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

})()