Greasy Fork is available in English.

Github Commit Whitespace

Adds button to hide whitespaces from commit

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

  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. // @include https://github.com/*
  11. // @version 1.2.1
  12. // @grant none
  13. // ==/UserScript==
  14. /* global unsafeWindow */
  15.  
  16. (function() {
  17.  
  18. function addButton() {
  19. var e;
  20. if (!(/\/commit\//.test(location.href) || /\/compare\//.test(location.href) || /\/pull\/\d*\/files/.test(location.href)) ||
  21. !(e = document.querySelector("#toc .explain"))) { return; }
  22.  
  23. var r = e.querySelector(".GithubCommitWhitespaceButton");
  24. if (r) { r.parentElement.removeChild(r); }
  25.  
  26. var on = /w=/.test(location.search);
  27.  
  28. var b = e.querySelector(".minibutton");
  29.  
  30. var s = document.createElement("span");
  31. s.textContent = " \u2423";
  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("GithubCommitWhitespaceButton", "minibutton", "tooltipped", "tooltipped-s");
  36. if (on) { a.classList.add("selected"); }
  37. a.setAttribute("href", on ? location.href.replace(location.search, "") : location.href + "?w=1");
  38. a.setAttribute("title", on ? "Show commit whitespace" : "Hide commit whitespaces");
  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.  
  44. b.parentNode.insertBefore(a, b);
  45. }
  46.  
  47. // init;
  48. addButton();
  49.  
  50. // on pjax;
  51. unsafeWindow.$(document).on("pjax:success", addButton);
  52.  
  53. // on PR files tab;
  54. var f;
  55. if ((f = document.querySelector(".js-pull-request-tab[data-container-id='files_bucket']"))) {
  56. f.addEventListener("click", function() {
  57. window.setTimeout(addButton, 13);
  58. });
  59. }
  60.  
  61. })();