Greasy Fork is available in English.

Github Commit Diff

Adds button to show diff (or patch) file for commit

ของเมื่อวันที่ 27-02-2014 ดู เวอร์ชันล่าสุด

  1. // ==UserScript==
  2. // @name Github Commit Diff
  3. // @namespace https://github.com/jerone/UserScripts
  4. // @description Adds button to show diff (or patch) file for commit
  5. // @author jerone
  6. // @homepage https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
  7. // @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Commit_Diff
  8. // @include http*://github.com/*
  9. // @version 1
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13.  
  14. (function(){
  15.  
  16. function addButton() {
  17. if(!/\/commit\//.test(location.href) || !document.querySelector(".explain")) return;
  18. var r;
  19. if((r = document.querySelector(".GithubCommitDiffButton"))) r.parentElement.removeChild(r);
  20. function getPatchOrDiffHref(type){
  21. return (document.querySelector("link[type='text/plain+" + type + "']")
  22. || { href: location.href + "." + type }).href;
  23. };
  24. var b = document.querySelector(".explain .minibutton");
  25. var s = document.createElement("span");
  26. s.textContent = " ";
  27. s.classList.add("octicon", "octicon-diff");
  28. s.style.color = "#333"; // set color because of css selector `p.explain .octicon`;
  29. var a = document.createElement("a");
  30. a.classList.add("GithubCommitDiffButton", "minibutton", "tooltipped", "tooltipped-s");
  31. a.setAttribute("href", getPatchOrDiffHref("diff"));
  32. a.setAttribute("title", "Show commit diff.\r\nHold Shift to open commit patch.");
  33. a.setAttribute("rel", "nofollow");
  34. a.setAttribute("aria-label", a.getAttribute("title"));
  35. a.style.marginLeft = "10px"; // give us some room;
  36. a.appendChild(s);
  37. a.appendChild(document.createTextNode("Diff"));
  38. b.parentNode.insertBefore(a, b);
  39. a.addEventListener("click", function(e){
  40. if(e.shiftKey) {
  41. e.preventDefault();
  42. location.href = getPatchOrDiffHref("patch");
  43. }
  44. }, false);
  45. }
  46. // init;
  47. addButton();
  48. // on pjax;
  49. $(document).on('pjax:success', addButton);
  50.  
  51. })();