BBC: article word count
Appends the article word count next to the title so you immediately know how long the text is.
Code to copy
// Show a word count of the article next to the headline
(function () {
if (document.getElementById('jz-bbc-wordcount')) { return; }
var blocks = document.querySelectorAll('[data-component="text-block"]');
if (!blocks.length) { return; }
var words = 0;
blocks.forEach(function (b) {
words += (b.textContent || '').trim().split(/\s+/).length;
});
var h1 = document.querySelector('article h1') || document.querySelector('h1');
if (!h1) { return; }
var tag = document.createElement('span');
tag.id = 'jz-bbc-wordcount';
tag.textContent = ' (' + words + ' words)';
tag.style.cssText = 'font-size:0.8em;color:#888;font-weight:400';
h1.appendChild(tag);
})();
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- 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.