← All examples

JavaScript Reading & focus

Estimated reading time badge

Counts the article words and shows a corner badge with the estimated reading time at 220 words per minute.

Code to copy

(function () {
  var article = document.querySelector('article, .post, .entry-content, main');
  if (!article) return;
  var words = (article.innerText || '').trim().split(/\s+/).filter(Boolean).length;
  if (words === 0) return;
  var minutes = Math.max(1, Math.round(words / 220));
  var badge = document.createElement('div');
  badge.textContent = '~' + minutes + ' min read';
  badge.style.cssText = 'position:fixed;top:12px;right:12px;z-index:999999;' +
    'background:#5b4636;color:#fff;font:600 13px/1 sans-serif;' +
    'padding:6px 10px;border-radius:6px;box-shadow:0 2px 6px rgba(0,0,0,.25);';
  document.body.appendChild(badge);
})();

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Paste the code into the rule's JavaScript panel and save — it runs on every page visit.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases