calculateReadingTime is a lightweight and efficient JavaScript package designed to calculate the estimated reading time of any given text. This unique package dynamically adjusts based on font size and content length, making it ideal for blog posts, articles, and content-heavy websites.
To use this JavaScript reading time calculator, simply include the following CDN in your HTML file:
<script src="https://cdn.jsdelivr.net/gh/sumeetghimire/calculateReadingTime/index.js"></script>
Wrap your text inside a container element for the reading time estimator:
<div id="content">
<p>This is a sample text for reading time estimation.</p>
</div>
Create an element to display the calculated reading time dynamically:
<div id="reading-time"></div>
Invoke the displayReadingTime
function to calculate and display reading time in the target element:
<script>
window.onload = function() {
displayReadingTime('reading-time');
}
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reading Time Test</title>
<script src="https://cdn.jsdelivr.net/gh/sumeetghimire/calculateReadingTime/index.js"></script>
</head>
<body>
<div id="content">
<p>This text demonstrates how to calculate reading time dynamically using JavaScript.</p>
</div>
<div id="reading-time"></div>
<script>
window.onload = function() {
displayReadingTime('reading-time');
}
</script>
</body>
</html>
This JavaScript reading time calculator is open-source and licensed under the MIT License.