Skip to content
(function () {
var bar = document.createElement('div');
bar.id = 'read-progress';
document.body.appendChild(bar);
var label = document.createElement('div');
label.id = 'read-progress-label';
label.textContent = '0%';
document.body.appendChild(label);
function updateProgress() {
var doc = document.documentElement;
var scrollTop = doc.scrollTop || document.body.scrollTop;
var scrollHeight = (doc.scrollHeight || 0) - doc.clientHeight;
var pct = scrollHeight > 0 ? (scrollTop / scrollHeight) * 100 : 0;
pct = Math.max(0, Math.min(100, pct));
bar.style.width = pct + '%';
label.textContent = Math.round(pct) + '%';
}
var ticking = false;
function onScroll() {
if (!ticking) {
window.requestAnimationFrame(function () {
updateProgress();
ticking = false;
});
ticking = true;
}
}
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', updateProgress);
document.addEventListener('DOMContentLoaded', updateProgress);
updateProgress();
})();