Greasy Fork is available in English.

Github Commit Whitespace

Adds button to hide whitespaces from commit

נכון ליום 24-05-2015. ראה הגרסה האחרונה.

  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. // @include https://github.com/*
  13. // @version 1.4.2
  14. // @grant none
  15. // ==/UserScript==
  16. /* global unsafeWindow */
  17.  
  18. (function() {
  19.  
  20. function addButton() {
  21. var e;
  22. if (!(/\/commit\//.test(location.href) || /\/compare\//.test(location.href) || /\/pull\/\d*\/files/.test(location.href)) ||
  23. !(e = document.getElementById("toc"))) { return; }
  24.  
  25. var r = e.querySelector(".GithubCommitWhitespaceButton");
  26. if (r) { r.parentElement.removeChild(r); }
  27.  
  28. var on = /w=/.test(location.search); // any occurense results in enabling;
  29.  
  30. var b = e.querySelector(".toc-diff-stats");
  31.  
  32. var s = document.createElement("span");
  33. s.textContent = " \u2423";
  34. s.style.color = "#333"; // set color because of css selector `p.explain .octicon`;
  35.  
  36. var a = document.createElement("a");
  37. a.classList.add("btn", "btn-sm", "tooltipped", "tooltipped-n");
  38. if (on) { a.classList.add("selected"); }
  39. a.setAttribute("href", url(on));
  40. a.setAttribute("rel", "nofollow");
  41. a.setAttribute("aria-label", on ? "Show commit whitespace" : "Hide commit whitespaces");
  42. a.appendChild(s);
  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. }
  51.  
  52. function url(on) {
  53. var searches = location.search.replace(/^\?/, "").split("&").filter(function(item) {
  54. return item && !/w=.*/.test(item);
  55. });
  56. if (!on) {
  57. searches.push("w=1");
  58. }
  59. return location.href.replace(location.search, "")
  60. + (searches.length > 0 ? "?" + searches.join("&") : "");
  61. }
  62.  
  63. // init;
  64. addButton();
  65.  
  66. // on pjax;
  67. unsafeWindow.$(document).on("pjax:end", addButton); // `pjax:end` also runs on history back;
  68.  
  69. // on PR files tab;
  70. var f;
  71. if ((f = document.querySelector(".js-pull-request-tab[data-container-id='files_bucket']"))) {
  72. f.addEventListener("click", function() {
  73. window.setTimeout(addButton, 13);
  74. });
  75. }
  76.  
  77. })();