Skip to content

Commit 15fce33

Browse files
committed
Updated Github Commit Diff
1 parent f0c72f2 commit 15fce33

3 files changed

Lines changed: 58 additions & 48 deletions

File tree

Github_Commit_Diff/Github_Commit_Diff.user.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,56 @@
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(!/\/commit\//.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 (!/\/commit\//.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
})();

Github_Commit_Diff/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ Adds button to show diff file for commit. Hold Shift key to open the patch file.
88

99
### Screenshot
1010

11-
-
11+
![Github Commit Diff screenshot](https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff/Github_Commit_Diff/screenshot.jpg)
1212

1313
### Compatible
1414

1515
* [![](https://raw.github.com/jerone/UserScripts/master/_resources/Greasemonkey.png) Greasemonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/) on [![](https://raw.github.com/jerone/UserScripts/master/_resources/Firefox.png) Mozilla Firefox Desktop](http://www.mozilla.org/en-US/firefox/fx/#desktop).
1616

1717
<sub>Please [notify](https://github.com/jerone/UserScripts/issues/new?title=Userscript%20%3Cname%3E%20%28%3Cversion%3E%29%20also%20works%20in%20%3Cbrowser%3E%20on%20%3Cdesktop/device%3E) when this userscript is successfully tested in another browser...</sub>
1818

19+
### Version History
20+
21+
<dl>
22+
<dt>1.1</dt>
23+
<dd>Clean up</dd>
24+
<dt>1.0</dt>
25+
<dd>Initial version</dd>
26+
</dl>
27+
1928
### Notes
2029

2130
-

Github_Commit_Diff/screenshot.jpg

34.2 KB
Loading

0 commit comments

Comments
 (0)