|
10 | 10 | // @downloadURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Whitespace/Github_Commit_Whitespace.user.js |
11 | 11 | // @updateURL https://github.com/jerone/UserScripts/raw/master/Github_Commit_Whitespace/Github_Commit_Whitespace.user.js |
12 | 12 | // @include https://github.com/* |
13 | | -// @version 1.3 |
| 13 | +// @version 1.4 |
14 | 14 | // @grant none |
15 | 15 | // ==/UserScript== |
16 | 16 | /* global unsafeWindow */ |
|
27 | 27 |
|
28 | 28 | var on = /w=/.test(location.search); |
29 | 29 |
|
30 | | - var b = e.querySelector(".minibutton"); |
| 30 | + var b = e.querySelector(".toc-diff-stats"); |
31 | 31 |
|
32 | 32 | var s = document.createElement("span"); |
33 | 33 | s.textContent = " \u2423"; |
34 | 34 | s.style.color = "#333"; // set color because of css selector `p.explain .octicon`; |
35 | 35 |
|
36 | 36 | var a = document.createElement("a"); |
37 | | - a.classList.add("GithubCommitWhitespaceButton", "minibutton", "right", "tooltipped", "tooltipped-s"); |
| 37 | + a.classList.add("minibutton", "tooltipped", "tooltipped-s"); |
38 | 38 | 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)); |
40 | 40 | a.setAttribute("title", on ? "Show commit whitespace" : "Hide commit whitespaces"); |
41 | 41 | a.setAttribute("rel", "nofollow"); |
42 | 42 | a.setAttribute("aria-label", a.getAttribute("title")); |
43 | | - a.style.marginLeft = "10px"; // give us some room; |
44 | 43 | a.appendChild(s); |
45 | 44 |
|
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("&") : ""); |
47 | 62 | } |
48 | 63 |
|
49 | 64 | // init; |
|
0 commit comments