GitHub Remove Diff Signs

A userscript that removes the "+" and "-" from code diffs

当前为 2017-04-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Remove Diff Signs
  3. // @version 1.1.3
  4. // @description A userscript that removes the "+" and "-" from code diffs
  5. // @license https://creativecommons.org/licenses/by-sa/4.0/
  6. // @author Rob Garrison
  7. // @namespace https://github.com/Mottie
  8. // @include https://github.com/*
  9. // @run-at document-idle
  10. // @grant none
  11. // @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=188072
  12. // @icon https://github.com/fluidicon.png
  13. // ==/UserScript==
  14. (() => {
  15. "use strict";
  16.  
  17. function processDiff() {
  18. if (document.querySelector(".highlight")) {
  19. let indx = 0,
  20.  
  21. els = document.querySelectorAll(`
  22. .blob-code-deletion .blob-code-inner,
  23. .blob-code-addition .blob-code-inner`
  24. ),
  25. len = els.length,
  26.  
  27. // target "+" and "-" at start
  28. regex = /^[+-]/,
  29.  
  30. // loop with delay to allow user interaction
  31. loop = () => {
  32. let el, txt,
  33. // max number of DOM insertions per loop
  34. max = 0;
  35. while ( max < 50 && indx < len ) {
  36. if (indx >= len) {
  37. return;
  38. }
  39. el = els[indx];
  40. txt = el.childNodes[0].textContent;
  41. el.childNodes[0].textContent = txt.replace(regex, " ");
  42. max++;
  43. indx++;
  44. }
  45. if (indx < len) {
  46. setTimeout(() => {
  47. loop();
  48. }, 200);
  49. }
  50. };
  51. loop();
  52. }
  53. }
  54.  
  55. // Observe GitHub dynamic content
  56. document.addEventListener("ghmo:container", init);
  57. document.addEventListener("ghmo:diff", processDiff);
  58.  
  59. function init() {
  60. if (document.querySelector("#files.diff-view")) {
  61. processDiff();
  62. }
  63. }
  64.  
  65. init();
  66.  
  67. })();