Greasy Fork is available in English.

Github Commit Whitespace

Adds button to hide whitespaces from commit

2016-08-17 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Github Commit Whitespace
  3. // @namespace https://github.com/jerone/UserScripts
  4. // @description Adds button to hide whitespaces from commit
  5. // @author jerone
  6. // @copyright 2014+, jerone (http://jeroenvanwarmerdam.nl)
  7. // @license GNU GPLv3
  8. // @homepage https://github.com/jerone/UserScripts/tree/master/Github_Commit_Whitespace
  9. // @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Commit_Whitespace
  10. // @supportURL https://github.com/jerone/UserScripts/issues
  11. // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
  12. // @icon https://github.com/fluidicon.png
  13. // @include https://github.com/*
  14. // @version 1.5.0
  15. // @grant none
  16. // ==/UserScript==
  17. /* global unsafeWindow */
  18.  
  19. (function() {
  20.  
  21. function addButton() {
  22. var e;
  23. if ((/\/commit\//.test(location.href) || /\/compare\//.test(location.href)) && (e = document.getElementById("toc"))) {
  24.  
  25. var r = e.querySelector(".GithubCommitWhitespaceButton");
  26. if (r) {
  27. r.parentElement.removeChild(r);
  28. }
  29.  
  30. var on = /w=/.test(location.search); // any occurense results in enabling;
  31.  
  32. var b = e.querySelector(".toc-diff-stats");
  33.  
  34. var a = document.createElement("a");
  35. a.classList.add("btn", "btn-sm", "tooltipped", "tooltipped-n");
  36. if (on) {
  37. a.classList.add("selected");
  38. }
  39. a.setAttribute("href", url(on));
  40. a.setAttribute("rel", "nofollow");
  41. a.setAttribute("aria-label", on ? "Show commit whitespace" : "Hide commit whitespace");
  42. a.appendChild(document.createTextNode(" \u2423"));
  43.  
  44. var g = document.createElement("div");
  45. g.classList.add("GithubCommitWhitespaceButton", "right");
  46. g.style.margin = "0 10px 0 0"; // give us some room;
  47. g.appendChild(a);
  48.  
  49. b.parentNode.insertBefore(g, b);
  50. } else if (/\/pull\/\d*\/(files|commits)/.test(location.href) && (e = document.querySelector("#files_bucket .pr-toolbar .diffbar > .float-right"))) {
  51.  
  52. var r = e.querySelector(".GithubCommitWhitespaceButton");
  53. if (r) {
  54. r.parentElement.removeChild(r);
  55. }
  56.  
  57. var on = /w=/.test(location.search); // any occurense results in enabling;
  58.  
  59. var a = document.createElement("a");
  60. a.classList.add("btn-link", "muted-link");
  61. a.setAttribute("href", url(on));
  62. a.setAttribute("rel", "nofollow");
  63. a.setAttribute("aria-label", on ? "Show commit whitespace" : "Hide commit whitespace");
  64. a.appendChild(document.createTextNode(on ? "Show whitespace" : "Hide whitespace"));
  65.  
  66. var g = document.createElement("div");
  67. g.classList.add("GithubCommitWhitespaceButton", "diffbar-item");
  68. g.appendChild(a);
  69.  
  70. e.insertBefore(g, e.firstChild);
  71. }
  72. }
  73.  
  74. function url(on) {
  75. var searches = location.search.replace(/^\?/, "").split("&").filter(function(item) {
  76. return item && !/w=.*/.test(item);
  77. });
  78. if (!on) {
  79. searches.push("w=1");
  80. }
  81. return location.href.replace(location.search, "") + (searches.length > 0 ? "?" + searches.join("&") : "");
  82. }
  83.  
  84. // init;
  85. addButton();
  86.  
  87. // on pjax;
  88. document.addEventListener('pjax:end', addButton);
  89.  
  90. })();