Follow-up. I asked Google Gemini to modify the javascript code, to add the feature of searching for all instances of "Expand Full Comment" and click on them. Seems to work. Code is:
- - - -
javascript: (() => {
const maxClicks = 400;
let clickCount = 0;
const escapeHandler = (e) => {
if (e.key === "Escape") {
cleanup("Action stopped by user via Escape key.");
}
};
addEventListener("keydown", escapeHandler);
const intervalID = setInterval(() => {
/* 1. First, click all "Expand Full Comment" instances currently visible */
const expandText = "expand full comment";
const allElements = document.querySelectorAll("button, a, span, div");
allElements.forEach(el => {
if (el.textContent.toLowerCase().trim() === expandText) {
Thank you so much for publishing this! A year ago I had posted at reddit r/substack asking how to do something like this. user milahu referred me to this post. There is a substack I subscribe to with a weekly open thread (OT) that sometimes gets 3,000+ comments.
If I want to go back to a previous OT, not to *read* all the comments, but rather to *search* all the comments to find something I remember seeing/reading, I previously would have to repeatedly PageDown then click "Load More" multiple times, to get all the comments on screen. Only then could I do a valid text search. Your javascript bookmarklet code makes this much easier.
One suggestion, if interested, for a future improvement, is after all the comments are loaded, re-scan all the comments to look for "expand ful" (short for "expand full comment") because Substack initially only displays a portion of some particularly long comments. I manually have to search for these and click, to display the full amount of these long comments. The whole comment must be displayed for the text search to see all of the comment.
Follow-up. I asked Google Gemini to modify the javascript code, to add the feature of searching for all instances of "Expand Full Comment" and click on them. Seems to work. Code is:
- - - -
javascript: (() => {
const maxClicks = 400;
let clickCount = 0;
const escapeHandler = (e) => {
if (e.key === "Escape") {
cleanup("Action stopped by user via Escape key.");
}
};
addEventListener("keydown", escapeHandler);
const intervalID = setInterval(() => {
/* 1. First, click all "Expand Full Comment" instances currently visible */
const expandText = "expand full comment";
const allElements = document.querySelectorAll("button, a, span, div");
allElements.forEach(el => {
if (el.textContent.toLowerCase().trim() === expandText) {
el.click();
}
});
/* 2. Then, look for the "Load More" / "More Comments" button to trigger the next batch */
const allButtons = document.querySelectorAll(".comment-list-container button");
let targetButton = null;
for (const btn of allButtons) {
const text = btn.innerText.toLowerCase();
if (text.includes("more comments") || text.includes("load more")) {
targetButton = btn;
break;
}
}
if (targetButton && clickCount < maxClicks) {
targetButton.scrollIntoView({ behavior: "smooth", block: "nearest" });
targetButton.click();
clickCount++;
} else {
const msg =
clickCount >= maxClicks
? "Stopped: Click limit reached."
: "Finished: No more buttons found.";
cleanup(msg);
}
}, 2000);
function cleanup(message) {
clearInterval(intervalID);
removeEventListener("keydown", escapeHandler);
alert(message);
}
})();
- - - -
Thank you so much for publishing this! A year ago I had posted at reddit r/substack asking how to do something like this. user milahu referred me to this post. There is a substack I subscribe to with a weekly open thread (OT) that sometimes gets 3,000+ comments.
If I want to go back to a previous OT, not to *read* all the comments, but rather to *search* all the comments to find something I remember seeing/reading, I previously would have to repeatedly PageDown then click "Load More" multiple times, to get all the comments on screen. Only then could I do a valid text search. Your javascript bookmarklet code makes this much easier.
One suggestion, if interested, for a future improvement, is after all the comments are loaded, re-scan all the comments to look for "expand ful" (short for "expand full comment") because Substack initially only displays a portion of some particularly long comments. I manually have to search for these and click, to display the full amount of these long comments. The whole comment must be displayed for the text search to see all of the comment.
Regards,
Awesome! I hope it's useful. I've put it on my list to look into expanding the text of the long comments as well. Thanks for the suggestion!
all comments are stored in `<script>window._preloads = ...` so it should be possible to render all comments in one go
Yes, thanks for mentioning that. You can get the comments from the preloads and parse them.