website/static/js/readingTime.js

11 lines
355 B
JavaScript
Raw Normal View History

2023-06-13 20:13:00 +02:00
function readingTime() {
const text = document.querySelector("article").innerText;
const wpm = 225;
const words = text.trim().split(/\s+/).length;
const time = Math.ceil(words / wpm);
const timeElement = document.querySelector("span#readingTime");
timeElement.innerHTML = "<small> | </small>" + time + timeElement.innerHTML;
}
readingTime();