Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to load *all* comments when some are hidden due to number of comments #1892

Closed
pnkfelix opened this issue Mar 29, 2019 · 7 comments · Fixed by #2754
Closed

Add way to load *all* comments when some are hidden due to number of comments #1892

pnkfelix opened this issue Mar 29, 2019 · 7 comments · Fixed by #2754

Comments

@pnkfelix
Copy link

pnkfelix commented Mar 29, 2019

Look at rust-lang/rfcs#2544

Scroll down the the "Load more ..." (below "NNN hidden items" for some NNN).

The link there only loads some of the comments. It would be great to have a way to load all of them (e.g. it would help for people who then use search to find text in the page).

(I did try Alt-click; it did not work for me in this context.)

@fregante
Copy link
Member

This kinda makes sense because if I'm looking for something in those comments, chances are I want to check them all out. However we still need to limit this to, maybe 3 loads at a time, or else on the rare super-long discussion it might load too many pages nobody needs.

@pnkfelix
Copy link
Author

Here’s maybe a simpler request: could we add a “load more ...” button that is always in the same (hopefully easily accessible) location, eg right below the description, and just grated out when all are loaded, so that the work flow for loading all comments doesn’t involve repeatedly searching for the link after each load, and instead one can just sit and hit the button in one place until it’s all done?

@fregante
Copy link
Member

fregante commented Apr 1, 2019

I don’t think that can integrate nicely with the design.

@fregante
Copy link
Member

fregante commented Jun 6, 2019

This can just be added with alt+click, it will probably look a lot like infinite-scroll but instead of using IntersectionObserver it just waits for the click event.

@JeanMertz
Copy link

Funnily enough, I came searching for this feature request for the exact same reason (searching for a string in Rust RFCs, and not finding them because the comments are collapsed).

What makes this even more awkward is that searching for that string in the repo itself does return issues containing that string as a result, but then opening that issue, the string can no longer be found, because it is collapsed.

Personally, I'd like to have a "load all" button, or even better yet "always load all", but I can see how that might be detremental to page loading times (although the current workflow described by @pnkfelix of having to grep for "load more" clicking it, and repeating that several times takes way more time than an initial load all would cost).

@warpech
Copy link

warpech commented Nov 4, 2019

I would really appreciate this feature. For now, here's a recursive user script that works for me:

function loadAllComments() {
    let needRescheduling = false;
    const buttons = Array.from(document.querySelectorAll('button'));
    buttons.forEach((button) => {
        if (button.classList.contains('ajax-pagination-btn')) {
            if(!button.hasAttribute('disabled') && button.innerText === 'Load more…') {
                console.log("found", button);
                needRescheduling = true;
                button.dispatchEvent(new MouseEvent('click', {
                    bubbles: true,
                    cancelable: true
                }));                
            }
            else if(button.hasAttribute('disabled') && button.innerText === 'Loading…') {
                console.log("waiting", button);
                needRescheduling = true;
            }
            else {
                console.log("unrecognized 'Load more' button", button);
            }
        }
    });
    if (needRescheduling) {
        setTimeout(loadAllComments, 200)
    }
    else {
        console.log("all comments loaded");
    }
}

loadAllComments();

Here's a version that also expands "Show resolved" comments:

function loadAllCommentsAndShowResolved() {
  let needRescheduling = false;
  const elems = Array.from(document.querySelectorAll('button, .btn-link.Details-content--closed'));
  elems.forEach((elem) => {
    if (elem.classList.contains('ajax-pagination-btn')) {
      if (!elem.hasAttribute('disabled') && elem.innerText === 'Load more…') {
        console.log("found", elem);
        needRescheduling = true;
        elem.dispatchEvent(new MouseEvent('click', {
          bubbles: true,
          cancelable: true
        }));
      }
      else if (elem.hasAttribute('disabled') && elem.innerText === 'Loading…') {
        console.log("waiting", elem);
        needRescheduling = true;
      }
      else {
        console.log("unrecognized 'Load more' button", elem);
      }
    }
    else if (elem.classList.contains('Details-content--closed') && elem.innerText === 'Show resolved') {
      elem.dispatchEvent(new MouseEvent('click', {
        bubbles: true,
        cancelable: true
      }));
    }
  });
  if (needRescheduling) {
    setTimeout(loadAllCommentsAndShowResolved, 200)
  }
  else {
    console.log("all comments loaded");
  }
}

loadAllCommentsAndShowResolved();

Aaron1011 added a commit to Aaron1011/refined-github that referenced this issue Dec 12, 2019
Fixes refined-github#1892

Github has a "feature" that hides a large fraction of the comments in
long issue/PR threads, requiring the user to click a "Show hidden
button" to see them.

Not only can this cut off important parts of a
discussion, clicking the button only reveals *some* of the hidden
comments. To show the entire thread, a user must:

1. Search on the page for "show hidden"
2. Click the button
3. Wait several seconds for an AJAX request to complete and the page to
update
4. Go back to step 1 if there are more hidden comments

This must be done every time the user nagivates to an issue/PR page.

This PR adds a new feature called 'load-hidden-comments', which performs
this process automatically on page load. It dramatically speeds up the
process by modifiying the undocumented API request (github.com/_render_node/...)
used by the "Show hidden button". By increasing the "variables[first]"
query parameter from "60" to the total number of hidden requests, we can
load all hidden comments with a single HTTP request.

Since the URL being modified is undocumented, this trick could break at
any time. However, the alternative is to repeatedly click the (newly
generated) button after each partial comment fetch completes. This
takes *significantly* longer, and results in janky scrollbar behavior
due to comments being added one chunk at a time.
Aaron1011 added a commit to Aaron1011/refined-github that referenced this issue Dec 12, 2019
Fixes refined-github#1892

Github has a "feature" that hides a large fraction of the comments in
long issue/PR threads, requiring the user to click a "Show hidden
button" to see them.

Not only can this cut off important parts of a
discussion, clicking the button only reveals *some* of the hidden
comments. To show the entire thread, a user must:

1. Search on the page for "show hidden"
2. Click the button
3. Wait several seconds for an AJAX request to complete and the page to
update
4. Go back to step 1 if there are more hidden comments

This must be done every time the user nagivates to an issue/PR page.

This PR adds a new feature called 'load-hidden-comments', which performs
this process automatically on page load. It dramatically speeds up the
process by modifiying the undocumented API request (github.com/_render_node/...)
used by the "Show hidden button". By increasing the "variables[first]"
query parameter from "60" to the total number of hidden requests, we can
load all hidden comments with a single HTTP request.

Since the URL being modified is undocumented, this trick could break at
any time. However, the alternative is to repeatedly click the (newly
generated) button after each partial comment fetch completes. This
takes *significantly* longer, and results in janky scrollbar behavior
due to comments being added one chunk at a time.
@RentecAaron
Copy link

The above recursive script is outdated. Here's a script that will load all hidden comments, including resolved.

window.addEventListener('load', function () {
  loadComments();
})

let tryAttempts = 0;

function loadComments () {
	let needRescheduling = false;
	const buttons = document.querySelectorAll(".ajax-pagination-btn[data-disable-with]")
	
	buttons.forEach((button) => {
		button.click();
		needRescheduling = true;
		tryAttempts = 0;
	})
	
	if (needRescheduling || tryAttempts < 5) {
		if (needRescheduling) {
			console.log("Loading comments.")
		} else {
			console.log("Looking for more to load.");
		}
		tryAttempts++;
		setTimeout(loadComments, 500)
	} else {
		console.log("All comments loaded.");

		const resolvedButtons = document.querySelectorAll(".js-toggle-outdated-comments[data-view-component]");

		resolvedButtons.forEach((button) => {
			button.click();
		})
		
		console.log("All resolved comments loaded.")
	}
}

@refined-github refined-github locked as resolved and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants