const anchors = [];
[...document.querySelectorAll('a')].forEach(($link) => {
let href = $link.getAttribute(`href`);
if (href.startsWith(window.location.href)) {
href = href.split(window.location.href).join(``);
}
if (href.startsWith(window.location.pathname)) {
href = href.split(window.location.pathname).join(``);
}
if (href !== `#` && href.startsWith(`#`)) {
anchors.push({
href,
text: $link.textConent,
});
}
});
console.log(anchors);