forked from jerone/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGithub_Commit_Whitespace.user.js
More file actions
91 lines (74 loc) · 3.59 KB
/
Copy pathGithub_Commit_Whitespace.user.js
File metadata and controls
91 lines (74 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// ==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
// @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Whitespace/Github_Commit_Whitespace.user.js
// @updateURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Whitespace/Github_Commit_Whitespace.user.js
// @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.5.2
// @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, '') + (searches.length > 0 ? '?' + searches.join('&') : '')
}
// Init
addButton()
// Pjax
document.addEventListener('pjax:end', addButton)
})()