PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.7
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.7
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / reading-time / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.7, at blocks/reading-time/frontend.js

23 lines 999 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 document.addEventListener('DOMContentLoaded', function () {
3 var wraps = document.querySelectorAll('.bkrt-wrap[data-wpm]');
4 if (!wraps.length) return;
5
6 // Count words from the article/post content on the page
7 var contentEl = document.querySelector('article .entry-content, .post-content, .wp-block-post-content, main article, .site-main .hentry, body');
8 var rawText = contentEl ? contentEl.innerText || contentEl.textContent : document.body.innerText;
9 var wordCount = rawText.trim().split(/\s+/).filter(Boolean).length;
10
11 wraps.forEach(function (wrap) {
12 var wpm = parseInt(wrap.dataset.wpm, 10) || 200;
13 var prefix = wrap.dataset.prefix || '';
14 var suffix = wrap.dataset.suffix || 'min read';
15 var mins = Math.max(1, Math.ceil(wordCount / wpm));
16 var textEl = wrap.querySelector('.bkrt-text');
17 if (textEl) {
18 textEl.textContent = (prefix ? prefix + ' ' : '') + mins + ' ' + suffix;
19 }
20 });
21 });
22 }() );
23