This snippet removes some of the empty a
elements to make the headings anchors instead:
javascript
([ ...document.querySelectorAll("a[name] +h1, a[name] +h2, a[name] +h3, a[name] +h4, h1 +a[name], h2 +a[name], h3 +a[name], h4 +a[name]") ]).map((x) => {
if (x instanceof HTMLHeadingElement) {
var link = x.previousElementSibling;
var heading = x;
} else {
var link = x;
var heading = x.previousElementSibling;
}
link.parentElement.removeChild(link);
heading.setAttribute("id", link.name);
})