← All posts

Tutorials

Build your own reader mode — strip a page to its content

Browsers have a reader mode, but it is hit-or-miss — on one page it does not trigger, on another it cuts too much, and you cannot tune it. In JustZix you build your own: one action button that strips the page to the article itself, by your rules.

Why your own

The built-in reader mode is a black box. You do not know when it appears, you cannot influence what it considers "content", you cannot change the typography. Your own rule is a dozen lines you understand and adjust to your taste.

Best as a BUTTON action

You rarely want reader mode on automatically — you want it on demand. That makes it an ideal candidate for a BUTTON action in the JustZix action bar. Label it, say, READ, with code that runs on click:

const art = document.querySelector(
  'article, [role="main"], main, .entry-content, .post-content'
);
if (!art) { alert('No content container found.'); }
else {
  document.body.replaceChildren(art);
  document.body.style.cssText =
    'max-width:70ch;margin:40px auto;padding:0 24px;' +
    'font:19px/1.7 Georgia, serif;background:#fbfaf7;color:#222';
}

How it works

Picking the content container

querySelector gets a list of candidates from most to least reliable: <article>, an element with role="main", <main>, then common CMS classes. It takes the first that exists. For a page where nothing matches, add its own selector to the front of the list.

replaceChildren

document.body.replaceChildren(art) throws everything out of <body> and puts only the article container there. One call instead of a loop removing element after element.

Typography

max-width:70ch gives a line about 70 characters long — the readability optimum. The rest is margin, a serif font and a warm background. Change it to your taste.

The CSS-only variant

If the page has a clean <article>, you can skip the JS — in the rule's CSS tab:

body > *:not(:has(article)) { display: none !important; }
article {
  max-width: 70ch !important;
  margin: 40px auto !important;
  font-size: 19px !important;
  line-height: 1.7 !important;
}

The CSS variant is less reliable (it depends on the page structure) but it does not touch the DOM — easy to switch off.

Pitfalls

See also

Install JustZix — and read articles without the rest of the page.

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