← All posts

Tutorials

Auto-expand show more, spoilers and comments

Comment sections collapsed to three entries. Long posts cut off with "read more". FAQs hidden in accordions. The content is on the page — just stashed behind a button. This rule clicks all those buttons for you.

The pattern

Expand buttons have one of two tells: text like "show more" / "read more", or an aria-expanded="false" attribute. The rule catches both and clicks.

The rule

The rule's JavaScript:

const RE = /show more|read more|see more|expand|view all/i;

function expandAll() {
  document.querySelectorAll('button, a, [role="button"]').forEach(el => {
    if (el.dataset.jzExpanded) return;
    const hit = RE.test(el.textContent || '')
      || el.getAttribute('aria-expanded') === 'false';
    if (hit) {
      el.dataset.jzExpanded = '1';
      el.click();
    }
  });
}

expandAll();
new MutationObserver(expandAll)
  .observe(document.body, { childList: true, subtree: true });

How it works

A text regex plus aria-expanded

One regular expression, a few wording variants, the i flag ignores case. Independently we check aria-expanded="false" — the standard accordion attribute, which works even without matching text.

The jzExpanded marker

After clicking an element we set data-jz-expanded on it. Next time the function skips it. Without that marker we would loop: a click expands the section, the section changes the DOM, the MutationObserver fires the function, it clicks the same button again.

MutationObserver

Comments and lists often load after the page starts. The MutationObserver watches the whole <body> and calls expandAll every time something is added to the DOM — so buttons that did not exist at start get expanded too.

Pitfalls

See also

Install JustZix — and stop clicking "show more" over and over.

Rate this post

No ratings yet — be the first.

Try it yourself

Install JustZix and paste any snippet from this article. Two minutes from zero to a working rule across all your devices.

Get JustZix

Features · How it works · Examples · Use cases