66// @homepage https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
77// @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
88// @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Diff/Github_Commit_Diff.user.js
9- // @include http* ://github.com/*
10- // @version 1
9+ // @include https ://github.com/*
10+ // @version 1.1
1111// @grant none
1212// ==/UserScript==
1313
14- ( function ( ) {
15-
16- function addButton ( ) {
17- if ( ! / \/ c o m m i t \/ / . test ( location . href ) || ! document . querySelector ( ".explain" ) ) return ;
18-
19- var r ;
20- if ( ( r = document . querySelector ( ".GithubCommitDiffButton" ) ) ) r . parentElement . removeChild ( r ) ;
21-
22- function getPatchOrDiffHref ( type ) {
23- return ( document . querySelector ( "link[type='text/plain+" + type + "']" )
24- || { href : location . href + "." + type } ) . href ;
25- } ;
26-
27- var b = document . querySelector ( ".explain .minibutton" ) ;
28-
29- var s = document . createElement ( "span" ) ;
30- s . textContent = " " ;
31- s . classList . add ( "octicon" , "octicon-diff" ) ;
32- s . style . color = "#333" ; // set color because of css selector `p.explain .octicon`;
33-
34- var a = document . createElement ( "a" ) ;
35- a . classList . add ( "GithubCommitDiffButton" , "minibutton" , "tooltipped" , "tooltipped-s" ) ;
36- a . setAttribute ( "href" , getPatchOrDiffHref ( "diff" ) ) ;
37- a . setAttribute ( "title" , "Show commit diff.\r\nHold Shift to open commit patch." ) ;
38- a . setAttribute ( "rel" , "nofollow" ) ;
39- a . setAttribute ( "aria-label" , a . getAttribute ( "title" ) ) ;
40- a . style . marginLeft = "10px" ; // give us some room;
41- a . appendChild ( s ) ;
42- a . appendChild ( document . createTextNode ( "Diff" ) ) ;
43-
44- b . parentNode . insertBefore ( a , b ) ;
45-
46- a . addEventListener ( "click" , function ( e ) {
47- if ( e . shiftKey ) {
48- e . preventDefault ( ) ;
49- location . href = getPatchOrDiffHref ( "patch" ) ;
50- }
51- } , false ) ;
52- }
53-
54- // init;
55- addButton ( ) ;
56-
57- // on pjax;
58- $ ( document ) . on ( 'pjax:success' , addButton ) ;
14+ ( function ( ) {
15+
16+ function addButton ( ) {
17+ var e ;
18+ if ( ! / \/ c o m m i t \/ / . test ( location . href ) || ! ( e = document . querySelector ( ".explain" ) ) ) return ;
19+
20+ var r = e . querySelector ( ".GithubCommitWhitespaceButton" ) ;
21+ if ( r ) r . parentElement . removeChild ( r ) ;
22+
23+ function getPatchOrDiffHref ( type ) {
24+ return ( document . querySelector ( "link[type='text/plain+" + type + "']" )
25+ || { href : location . href + "." + type } ) . href ;
26+ } ;
27+
28+ var b = e . querySelector ( ".minibutton" ) ;
29+
30+ var s = document . createElement ( "span" ) ;
31+ s . textContent = " " ;
32+ s . classList . add ( "octicon" , "octicon-diff" ) ;
33+ s . style . color = "#333" ; // set color because of css selector `p.explain .octicon`;
34+
35+ var a = document . createElement ( "a" ) ;
36+ a . classList . add ( "GithubCommitDiffButton" , "minibutton" , "tooltipped" , "tooltipped-s" ) ;
37+ a . setAttribute ( "href" , getPatchOrDiffHref ( "diff" ) ) ;
38+ a . setAttribute ( "title" , "Show commit diff.\r\nHold Shift to open commit patch." ) ;
39+ a . setAttribute ( "rel" , "nofollow" ) ;
40+ a . setAttribute ( "aria-label" , a . getAttribute ( "title" ) ) ;
41+ a . style . marginLeft = "10px" ; // give us some room;
42+ a . appendChild ( s ) ;
43+ a . appendChild ( document . createTextNode ( "Diff" ) ) ;
44+
45+ b . parentNode . insertBefore ( a , b ) ;
46+
47+ a . addEventListener ( "click" , function ( e ) {
48+ if ( e . shiftKey ) {
49+ e . preventDefault ( ) ;
50+ location . href = getPatchOrDiffHref ( "patch" ) ;
51+ }
52+ } , false ) ;
53+ }
54+
55+ // init;
56+ addButton ( ) ;
57+
58+ // on pjax;
59+ $ ( document ) . on ( 'pjax:success' , addButton ) ;
5960
6061} ) ( ) ;
0 commit comments