预计阅读时间徽章
统计文章字数,在角落显示按每分钟220词估算的阅读时间徽章。
可复制的代码
(function () {
var article = document.querySelector('article, .post, .entry-content, main');
if (!article) return;
var words = (article.innerText || '').trim().split(/\s+/).filter(Boolean).length;
if (words === 0) return;
var minutes = Math.max(1, Math.round(words / 220));
var badge = document.createElement('div');
badge.textContent = '~' + minutes + ' min read';
badge.style.cssText = 'position:fixed;top:12px;right:12px;z-index:999999;' +
'background:#5b4636;color:#fff;font:600 13px/1 sans-serif;' +
'padding:6px 10px;border-radius:6px;box-shadow:0 2px 6px rgba(0,0,0,.25);';
document.body.appendChild(badge);
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。