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.

13 lines
461 B

  1. var wpm = 200; // Average reading rate in words per minute (WPM)
  2. var ps = document.querySelectorAll('p');
  3. var wordCount = 0;
  4. for (var i=0; i<ps.length; i++) {
  5. wordCount += ps[i].innerText.split(/\s+/).length;
  6. }
  7. var $time = document.querySelector('#post-body .dt-published');
  8. if ($time) {
  9. $time.style.display = 'inline-block';
  10. $time.insertAdjacentHTML("afterend", '<span style="color: #666"> &middot; ' + Math.round(wordCount / wpm) + ' min read</span>');
  11. }