Kaynağa Gözat

Add readtime.js widget

This script displays a "read time" on WriteFreely post pages. It appends
the time next to the date on the post.
main
Matt Baer 3 yıl önce
işleme
46980fd8bb
1 değiştirilmiş dosya ile 10 ekleme ve 0 silme
  1. +10
    -0
      readtime.js

+ 10
- 0
readtime.js Dosyayı Görüntüle

@@ -0,0 +1,10 @@
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');
$time.style.display = 'inline-block';
$time.insertAdjacentHTML("afterend", '<span class="dt-published"> &middot; ' + Math.round(wordCount / wpm) + ' min read</span>');

Yükleniyor…
İptal
Kaydet