← All examples

JavaScript Reading & focus

Article word counter

Shows a corner badge with the number of words and characters in the main article.

Code to copy

(function () {
  var article = document.querySelector('article, .post, .entry-content, main');
  if (!article) return;
  var text = (article.innerText || '').trim();
  var words = text ? text.split(/\s+/).filter(Boolean).length : 0;
  var chars = text.length;
  var badge = document.createElement('div');
  badge.textContent = words.toLocaleString() + ' words / ' +
    chars.toLocaleString() + ' chars';
  badge.style.cssText = 'position:fixed;bottom:12px;right:12px;z-index:999999;' +
    'background:#1a5fb4;color:#fff;font:600 12px/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