Collapse Unchanged Files

Collapse "Unchanged Files..." because they are annoying

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Collapse Unchanged Files
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Collapse "Unchanged Files..." because they are annoying
// @author       You
// @match        https://github.com/*/pull/*/files
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const triggerButton = document.createElement('button');
    triggerButton.textContent = 'Collapse Unchanged Files';
    triggerButton.classList.add('trigger-button'); // Add a CSS class for styling

    // Style the button (you can customize this)
    triggerButton.style.position = 'fixed';
    triggerButton.style.bottom = '20px';
    triggerButton.style.right = '20px';
    triggerButton.style.padding = '10px 20px';
    triggerButton.style.background = '#007bff';
    triggerButton.style.color = 'white';
    triggerButton.style.border = 'none';
    triggerButton.style.borderRadius = '5px';
    triggerButton.style.cursor = 'pointer';

    // Add an event listener to the button
    triggerButton.addEventListener('click', () => {
        // Your script logic here
        const h3Elements = document.querySelectorAll('h3');
        const targetH3 = Array.from(h3Elements).find(h3 => h3.innerText.includes('Unchanged files'));

        if (targetH3) {
            const parentElement = targetH3.parentElement;
            const buttons = parentElement.querySelectorAll('button[aria-label="Toggle diff contents"]:not([aria-expanded="false"])');

            buttons.forEach(button => {
                button.click();
            });
        }
    });

    // Append the button to the document body (or any other desired parent element)
    document.body.appendChild(triggerButton);
})();