Hide "GitHub Actions" Notifications in PR Conversations

Hide "GitHub Actions" div elements on GitHub pull request page so other comments will not be hidden.

当前为 2023-12-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide "GitHub Actions" Notifications in PR Conversations
  3. // @namespace https://github.com/thinkall/
  4. // @version 0.1
  5. // @description Hide "GitHub Actions" div elements on GitHub pull request page so other comments will not be hidden.
  6. // @author thinkall
  7. // @match https://github.com/*/pull/*
  8. // @grant none
  9. // @source https://github.com/thinkall/tinytools
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to hide elements with specified class names, except the last one
  17. function hideElementsExceptLast(className) {
  18. var elements = document.getElementsByClassName(className);
  19.  
  20. // Hide all elements except the last one
  21. for (var i = 0; i < elements.length - 1; i++) {
  22. elements[i].style.display = 'none';
  23. }
  24. }
  25.  
  26. // Function to click the "Load more" button
  27. function clickLoadMore() {
  28. var loadMoreButton = document.querySelector('.ajax-pagination-btn');
  29. if (loadMoreButton) {
  30. loadMoreButton.click();
  31. }
  32. }
  33.  
  34. // Function to observe changes in the DOM and hide newly loaded elements
  35. function observeDOM() {
  36. var targetNode = document.body;
  37.  
  38. var observerOptions = {
  39. childList: true, // Report changes to child elements
  40. subtree: true, // Include all descendants of the target node
  41. };
  42.  
  43. var mutationObserver = new MutationObserver(function(mutations) {
  44. mutations.forEach(function(mutation) {
  45. if (mutation.addedNodes && mutation.addedNodes.length > 0) {
  46. // Newly added nodes, check and hide elements
  47. hideElementsExceptLast(classNamesToHide[0]);
  48. }
  49. });
  50. });
  51.  
  52. mutationObserver.observe(targetNode, observerOptions);
  53. }
  54.  
  55. // List of class names to hide
  56. var classNamesToHide = [
  57. 'TimelineItem js-targetable-element',
  58. // Add more class names as needed
  59. ];
  60.  
  61. // Wait for the page to load completely
  62. window.addEventListener('load', function() {
  63. // Initial hiding of elements, except the last one
  64. hideElementsExceptLast(classNamesToHide[0]);
  65.  
  66. // Start observing changes in the DOM
  67. observeDOM();
  68.  
  69. // Click "Load more" repeatedly until not visible
  70. var loadMoreInterval = setInterval(function() {
  71. clickLoadMore();
  72. }, 1000); // Adjust the interval as needed, e.g., 1000 milliseconds (1 second)
  73. });
  74. })();