Widget for displaying "reading time" on WriteFreely posts.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- var wpm = 200; // Average reading rate in words per minute (WPM)
-
- var ps = document.querySelectorAll('p');
- var wordCount = 0;
- for (var i=0; i<ps.length; i++) {
- wordCount += ps[i].innerText.split(/\s+/).length;
- }
- var $time = document.querySelector('#post-body .dt-published');
- if ($time) {
- $time.style.display = 'inline-block';
- $time.insertAdjacentHTML("afterend", '<span style="color: #666"> · ' + Math.round(wordCount / wpm) + ' min read</span>');
- }
|