GitHub PR Load All Comments

Adds "Load all!" button to load all hidden conversations in GitHub PRs

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GitHub PR Load All Comments
// @namespace    http://tampermonkey.net/
// @icon         https://github.githubassets.com/favicons/favicon-dark.png
// @version      1.0.2
// @description  Adds "Load all!" button to load all hidden conversations in GitHub PRs
// @author       KakkoiDev
// @match        https://github.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

// Broad @match needed: GitHub uses SPA navigation, so navigating to a PR
// doesn't reload the page. MutationObserver handles detecting "Load more" buttons.

(function() {
    'use strict';

    let isLoadingAll = false;

    function getLoadMoreButtons() {
        return [...document.querySelectorAll('button')].filter(btn =>
            btn.textContent.trim().toLowerCase().includes('load more')
        );
    }

    function clickAllLoadMore() {
        const buttons = getLoadMoreButtons();
        buttons.forEach(btn => btn.click());
        return buttons.length;
    }

    function addLoadAllButtons() {
        const buttons = getLoadMoreButtons();
        buttons.forEach(btn => {
            const parent = btn.parentElement;
            if (!parent || parent.querySelector('.load-all-btn')) return;

            const loadAllBtn = document.createElement('button');
            loadAllBtn.type = 'button';
            loadAllBtn.className = btn.className + ' load-all-btn';
            loadAllBtn.textContent = 'Load all!';

            loadAllBtn.addEventListener('click', (e) => {
                e.preventDefault();
                e.stopPropagation();
                isLoadingAll = true;
                clickAllLoadMore();
            });

            parent.appendChild(loadAllBtn);
        });

        if (isLoadingAll && buttons.length > 0) {
            clickAllLoadMore();
        }
    }

    addLoadAllButtons();

    const observer = new MutationObserver(() => {
        addLoadAllButtons();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();