Skip to content

Commit fefa4e0

Browse files
committed
* Fixed align & url issues with new split diffs (fixes jerone#25);
1 parent 44414d9 commit fefa4e0

4 files changed

Lines changed: 23 additions & 6 deletions

File tree

Github_Commit_Whitespace/Github_Commit_Whitespace.user.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Whitespace/Github_Commit_Whitespace.user.js
1111
// @updateURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Whitespace/Github_Commit_Whitespace.user.js
1212
// @include https://github.com/*
13-
// @version 1.3
13+
// @version 1.4
1414
// @grant none
1515
// ==/UserScript==
1616
/* global unsafeWindow */
@@ -27,23 +27,38 @@
2727

2828
var on = /w=/.test(location.search);
2929

30-
var b = e.querySelector(".minibutton");
30+
var b = e.querySelector(".toc-diff-stats");
3131

3232
var s = document.createElement("span");
3333
s.textContent = " \u2423";
3434
s.style.color = "#333"; // set color because of css selector `p.explain .octicon`;
3535

3636
var a = document.createElement("a");
37-
a.classList.add("GithubCommitWhitespaceButton", "minibutton", "right", "tooltipped", "tooltipped-s");
37+
a.classList.add("minibutton", "tooltipped", "tooltipped-s");
3838
if (on) { a.classList.add("selected"); }
39-
a.setAttribute("href", on ? location.href.replace(location.search, "") : location.href + "?w=1");
39+
a.setAttribute("href", url(on));
4040
a.setAttribute("title", on ? "Show commit whitespace" : "Hide commit whitespaces");
4141
a.setAttribute("rel", "nofollow");
4242
a.setAttribute("aria-label", a.getAttribute("title"));
43-
a.style.marginLeft = "10px"; // give us some room;
4443
a.appendChild(s);
4544

46-
b.parentNode.insertBefore(a, b);
45+
var g = document.createElement("div");
46+
g.classList.add("GithubCommitWhitespaceButton", "button-group", "right");
47+
g.style.margin = "0 10px 0 0"; // give us some room;
48+
g.appendChild(a);
49+
50+
b.parentNode.insertBefore(g, b);
51+
}
52+
53+
function url(on) {
54+
var searches = location.search.replace(/^\?/, "").split("&").filter(function(item) {
55+
return item && !/w=.*/.test(item);
56+
});
57+
if (!on) {
58+
searches.push("w=1");
59+
}
60+
return location.href.replace(location.search, "")
61+
+ (searches.length > 0 ? "?" + searches.join("&") : "");
4762
}
4863

4964
// init;

Github_Commit_Whitespace/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Adds button to hide whitespaces from commit.
2222

2323
### Version History
2424

25+
* **1.4**
26+
* Fixed align & url issues with new split diffs (fixes https://github.com/jerone/UserScripts/issues/25);
2527
* **1.3**
2628
* Fixed issues after recent layout updates (fixes https://github.com/jerone/UserScripts/issues/9);
2729
* **1.2.1**
-19.8 KB
Loading
-2.96 KB
Loading

0 commit comments

Comments
 (0)