window.addEventListener("scroll", (e) => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const elem = document.getElementById("target");
if (elem?.offsetTop <= scrollTop) {
document.location.hash = elem.id;
} else {
document.location.hash = '';
}
}, false);
block.forEach((el) => {
const pos = el.getBoundingClientRect();
if (pos.top < window.innerHeight / 2 && pos.bottom > 0) {
history.pushState(null, null, `#${el.id}`);
} else {
history.pushState(null, null, '');
}
});