GitHub Remove Diff Signs

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

当前为 2018-04-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Remove Diff Signs
  3. // @version 1.2.2
  4. // @description A userscript that removes the "+" and "-" from code diffs
  5. // @license MIT
  6. // @author Rob Garrison
  7. // @namespace https://github.com/Mottie
  8. // @include https://github.com/*
  9. // @run-at document-idle
  10. // @grant GM_addStyle
  11. // @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=264157
  12. // @icon https://assets-cdn.github.com/pinned-octocat.svg
  13. // ==/UserScript==
  14. (() => {
  15. "use strict";
  16.  
  17. GM_addStyle(`.diff-table .blob-code-inner:before {
  18. user-select: none;
  19. content: "\\a0";
  20. }`);
  21.  
  22. function processDiff() {
  23. if (document.querySelector(".highlight")) {
  24. let indx = 0,
  25. els = document.querySelectorAll(`span.blob-code-inner:not([data-ghrds])`),
  26. len = els.length;
  27.  
  28. // loop with delay to allow user interaction
  29. function loop() {
  30. let el, txt, firstNode,
  31. // max number of DOM insertions per loop
  32. max = 0;
  33. while ( max < 50 && indx < len ) {
  34. if (indx >= len) {
  35. return;
  36. }
  37. el = els[indx];
  38. if (!el.getAttribute("data-ghrds")) {
  39. firstNode = el.childNodes[0];
  40. txt = firstNode.textContent || "";
  41. // remove the leading +, - or first space
  42. // the github-code-show-whitespace.user.js script is applied
  43. firstNode.textContent = txt.slice(1);
  44. el.setAttribute("data-ghrds", true);
  45. }
  46. max++;
  47. indx++;
  48. }
  49. if (indx < len) {
  50. setTimeout(() => {
  51. loop();
  52. }, 200);
  53. }
  54. }
  55. loop();
  56. }
  57. }
  58.  
  59. // Observe GitHub dynamic content
  60. document.addEventListener("ghmo:container", init);
  61. document.addEventListener("ghmo:diff", processDiff);
  62.  
  63. function init() {
  64. if (document.querySelector("#files.diff-view")) {
  65. processDiff();
  66. }
  67. }
  68.  
  69. init();
  70.  
  71. })();