Hide "GitHub Actions" Notifications in PR Conversations

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Hide "GitHub Actions" Notifications in PR Conversations
// @namespace    https://github.com/thinkall/
// @version      0.1
// @description  Hide "GitHub Actions" div elements on GitHub pull request page so other comments will not be hidden.
// @author       thinkall
// @match        https://github.com/*/pull/*
// @grant        none
// @source       https://github.com/thinkall/tinytools
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide elements with specified class names, except the last one
    function hideElementsExceptLast(className) {
        var elements = document.getElementsByClassName(className);

        // Hide all elements except the last one
        for (var i = 0; i < elements.length - 1; i++) {
            elements[i].style.display = 'none';
        }
    }

    // Function to click the "Load more" button
    function clickLoadMore() {
        var loadMoreButton = document.querySelector('.ajax-pagination-btn');
        if (loadMoreButton) {
            loadMoreButton.click();
        }
    }

    // Function to observe changes in the DOM and hide newly loaded elements
    function observeDOM() {
        var targetNode = document.body;

        var observerOptions = {
            childList: true, // Report changes to child elements
            subtree: true,   // Include all descendants of the target node
        };

        var mutationObserver = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes && mutation.addedNodes.length > 0) {
                    // Newly added nodes, check and hide elements
                    hideElementsExceptLast(classNamesToHide[0]);
                }
            });
        });

        mutationObserver.observe(targetNode, observerOptions);
    }

    // List of class names to hide
    var classNamesToHide = [
        'TimelineItem js-targetable-element',
        // Add more class names as needed
    ];

    // Wait for the page to load completely
    window.addEventListener('load', function() {
        // Initial hiding of elements, except the last one
        hideElementsExceptLast(classNamesToHide[0]);

        // Start observing changes in the DOM
        observeDOM();

        // Click "Load more" repeatedly until not visible
        var loadMoreInterval = setInterval(function() {
            clickLoadMore();
        }, 1000); // Adjust the interval as needed, e.g., 1000 milliseconds (1 second)
    });
})();