|
1 | 1 | # Read Time Counter JS |
2 | 2 |
|
3 | | -Read Time Counter is a ***simple and robust*** reading time counter that **accurately** counts words, characters, and images in your content. |
| 3 | +Read Time Counter is a **simple and robust** reading time counter that **accurately** counts words, characters, and images in your content. |
4 | 4 |
|
5 | | -It calculates the estimated reading time for English, CKJ (Chinese, Korean, Japanese), and other Latin-based languages by combining text reading and image viewing times. |
| 5 | +It calculates the estimated reading time for English, CKJ (Chinese, Korean, Japanese), and other Latin-based languages by combining text reading and image viewing times. |
6 | 6 |
|
7 | | - |
| 7 | +## Features |
8 | 8 |
|
9 | | -## How to use? |
| 9 | +- Accurate word counting for English and Latin-based languages. |
| 10 | +- Character counting for CJK (Chinese, Korean, Japanese) languages. |
| 11 | +- Image viewing time calculation. |
| 12 | +- Customizable reading speeds and output targets. |
| 13 | +- Lightweight and easy to integrate. |
10 | 14 |
|
11 | | -Ways to include the script: |
| 15 | +## Installation |
12 | 16 |
|
13 | | -### 1. Directly embed the script |
| 17 | +You can include the script in your project in one of the following ways: |
14 | 18 |
|
15 | | -Embed the script on your page, ideally before the closing `</body>` tag, to ensure all elements are loaded before the script runs. |
| 19 | +### 1. CDN (Recommended) |
| 20 | + |
| 21 | +Add the following script tag to your HTML `<head>`: |
16 | 22 |
|
17 | 23 | ```html |
18 | | -<script> |
19 | | -// Paste the code of readtime.js here |
20 | | -</script> |
| 24 | +<script defer src="https://cdn.jsdelivr.net/gh/SPACESODA/readtimecounter@3.3.2/readtime.min.js"></script> |
21 | 25 | ``` |
22 | 26 |
|
23 | | -### 2. Host and link your own .js file |
| 27 | +### 2. Local File |
24 | 28 |
|
25 | | -Place this in the `<head>` with the `defer` attribute so it runs after the DOM is parsed: |
| 29 | +Download `readtime.js` and include it in your project: |
26 | 30 |
|
27 | 31 | ```html |
28 | | -<script defer src="readtime.js"></script> |
| 32 | +<script defer src="path/to/readtime.js"></script> |
29 | 33 | ``` |
30 | 34 |
|
31 | | -### 3. Use the CDN version |
| 35 | +### 3. Inline Script |
| 36 | + |
| 37 | +Copy the contents of `readtime.js` and embed it directly: |
32 | 38 |
|
33 | 39 | ```html |
34 | | -<script defer src="https://cdn.jsdelivr.net/gh/SPACESODA/readtimecounter@3.2.8/readtime.min.js"></script> |
| 40 | +<script> |
| 41 | + // Paste readtime.js code here |
| 42 | +</script> |
35 | 43 | ``` |
36 | 44 |
|
37 | | - |
| 45 | +## Usage |
38 | 46 |
|
39 | | -## Define the area |
| 47 | +### 1. Define the Content Area |
40 | 48 |
|
41 | | -Wrap your article content in an element with the attribute `id="readtimearea"`. |
| 49 | +Wrap your article or content in an element with the ID `readtimearea`. |
42 | 50 |
|
43 | | -**Note:** Only one `readtimearea` is supported per page. |
| 51 | +```html |
| 52 | +<article id="readtimearea"> |
| 53 | + <!-- Your content goes here --> |
| 54 | +</article> |
| 55 | +``` |
44 | 56 |
|
45 | | - |
| 57 | +> **Note:** Only one `readtimearea` is supported per page. |
46 | 58 |
|
47 | | -## Output elements |
| 59 | +### 2. Display the Output |
48 | 60 |
|
49 | | -Display the estimated reading time (in minutes) by adding an element with the `id="readtime"`. For example: `<span id="readtime"></span>` |
| 61 | +Add elements with specific IDs where you want the statistics to appear. |
50 | 62 |
|
51 | | -The script also outputs individual counts for: |
52 | | -• **Words:** Displayed in an element with `id="wordCount"`. |
53 | | -• **CKJ Characters:** Displayed in an element with `id="ckjCount"`. |
54 | | -• **Images:** Displayed in an element with `id="imgCount"`. |
55 | | -• **Combined Info:** For displaying a summary, use `id="hybridCount"`. |
| 63 | +| ID | Description | |
| 64 | +| :------------ | :--------------------------------------------------- | |
| 65 | +| `readtime` | Estimated reading time in minutes. | |
| 66 | +| `wordCount` | Total word count (English/Latin). | |
| 67 | +| `ckjCount` | Total CJK character count. | |
| 68 | +| `imgCount` | Total image count. | |
| 69 | +| `hybridCount` | A combined summary of words, characters, and images. | |
56 | 70 |
|
57 | | -Example: |
| 71 | +**Example:** |
58 | 72 |
|
59 | 73 | ```html |
60 | | -<p>This article takes around <span id="readtime"></span> minutes to read.</p> |
61 | | -<p class="note"> |
62 | | - There are |
63 | | - <span id="wordCount"></span> words, |
64 | | - <span id="ckjCount"></span> CJK characters, and |
65 | | - <span id="imgCount"></span> images in this article. |
66 | | -</p> |
67 | | -<p class="note">Summary: <span id="hybridCount"></span></p> |
68 | | -``` |
| 74 | +<p>Estimated reading time: <span id="readtime"></span> minutes</p> |
| 75 | + |
| 76 | +<div class="stats"> |
| 77 | + <span id="wordCount"></span> words | |
| 78 | + <span id="ckjCount"></span> characters | |
| 79 | + <span id="imgCount"></span> images |
| 80 | +</div> |
69 | 81 |
|
70 | | - |
| 82 | +<!-- Or use the summary --> |
| 83 | +<p><span id="hybridCount"></span></p> |
| 84 | +``` |
71 | 85 |
|
72 | | -## Configurations |
| 86 | +## Configuration |
73 | 87 |
|
74 | | -If you’re using the CDN version, you can override the default reading speed and time format like this: |
| 88 | +You can customize the reading speed and other settings by defining `window.readingTimeSettings` **before** the script loads (or simply ensure the script runs after this configuration). |
75 | 89 |
|
76 | 90 | ```html |
77 | | -<script defer src="https://cdn.jsdelivr.net/gh/SPACESODA/readtimecounter@3.2.8/readtime.min.js"></script> |
78 | 91 | <script> |
79 | 92 | window.readingTimeSettings = { |
80 | | - engSpeed: 225, // words per minute for English |
81 | | - charSpeed: 300, // characters per minute for CKJ |
82 | | - imgSpeed: 10, // seconds per image |
83 | | - timeFormat: "integer" // "decimal" or "integer" |
| 93 | + engSpeed: 230, // English words per minute |
| 94 | + charSpeed: 285, // CJK characters per minute |
| 95 | + imgSpeed: 8, // Seconds per image |
| 96 | + timeFormat: "decimal", // "decimal" or "integer" |
| 97 | + // Custom Selectors (optional) |
| 98 | + readTimeTarget: "readtime", |
| 99 | + wordCountTarget: "wordCount", |
| 100 | + ckjCountTarget: "ckjCount", |
| 101 | + imgCountTarget: "imgCount", |
| 102 | + hybridCountTarget: "hybridCount", |
| 103 | + readTimeArea: "readtimearea" |
84 | 104 | }; |
85 | 105 | </script> |
| 106 | +<!-- Include the script after settings --> |
| 107 | +<script defer src="https://cdn.jsdelivr.net/gh/SPACESODA/readtimecounter@3.3.2/readtime.min.js"></script> |
86 | 108 | ``` |
87 | 109 |
|
88 | | - |
| 110 | +### Default Settings |
89 | 111 |
|
90 | | -## Live Example on CodePen |
| 112 | +| Option | Type | Default | Description | |
| 113 | +| :----------- | :----- | :---------- | :----------------------------------------------- | |
| 114 | +| `engSpeed` | Number | `230` | Reading speed for English words (WPM). | |
| 115 | +| `charSpeed` | Number | `285` | Reading speed for CJK characters (CPM). | |
| 116 | +| `imgSpeed` | Number | `8` | Time allocated for viewing each image (seconds). | |
| 117 | +| `timeFormat` | String | `"decimal"` | Output format: `"decimal"` or `"integer"`. | |
91 | 118 |
|
92 | | -Visit: https://codepen.io/pen/EaxyZzG |
| 119 | +## Live Demo |
93 | 120 |
|
94 | | -📣 **Please feel free to comment, contribute and make the code better!** |
| 121 | +Check out the live example on CodePen: |
| 122 | +[https://codepen.io/pen/EaxyZzG](https://codepen.io/pen/EaxyZzG) |
95 | 123 |
|
96 | | - |
| 124 | +## Contributing |
97 | 125 |
|
98 | | ---- |
| 126 | +Please feel free to comment, contribute, and make the code better! |
99 | 127 |
|
100 | | -References: |
101 | | - |
102 | | -https://en.wikipedia.org/wiki/English_alphabet |
103 | | - |
104 | | -https://en.wikipedia.org/wiki/CJK_characters |
| 128 | +--- |
105 | 129 |
|
106 | | -https://en.wikipedia.org/wiki/Universal_Character_Set_characters |
| 130 | +### References |
107 | 131 |
|
108 | | - |
| 132 | +- [English Alphabet](https://en.wikipedia.org/wiki/English_alphabet) |
| 133 | +- [CJK Characters](https://en.wikipedia.org/wiki/CJK_characters) |
| 134 | +- [Universal Character Set](https://en.wikipedia.org/wiki/Universal_Character_Set_characters) |
0 commit comments