Show/Hide issue comments for GitHub Issues

Add floating button to show/hide issue comments of GitHub Issues, to see discussion events / references easier.

  1. // ==UserScript==
  2. // @name Show/Hide issue comments for GitHub Issues
  3. // @namespace http://kyanny.me/
  4. // @version 1.0.0
  5. // @description Add floating button to show/hide issue comments of GitHub Issues, to see discussion events / references easier.
  6. // @author Kensuke Nagae
  7. // @match https://github.com/*/*/issues/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. var button = document.createElement('button');
  15. button.setAttribute('style', 'position: fixed; top: 10px; right: 5px;');
  16. button.setAttribute('data-display', "block");
  17. var text = document.createTextNode('Show/Hide comments');
  18. button.appendChild(text);
  19.  
  20. button.onclick = function() {
  21. var display = button.getAttribute('data-display');
  22.  
  23. var comments = Array.prototype.slice.call(document.querySelectorAll('.js-comment-container'));
  24.  
  25. if (display === "hidden") {
  26. // Show
  27. Array.forEach(comments, function(comment) {
  28. comment.style = 'display: block';
  29. });
  30. button.setAttribute('data-display', "block");
  31. } else {
  32. // Hide
  33. Array.forEach(comments, function(comment) {
  34. comment.style = 'display: none';
  35. });
  36. button.setAttribute('data-display', "hidden");
  37. }
  38. };
  39.  
  40. document.body.appendChild(button);
  41. })();