Skip to content

Instantly share code, notes, and snippets.

@Ran-ying
Created January 30, 2023 20:26
Show Gist options
  • Save Ran-ying/4ef4aa1b097081eae204a3a4c9b85aeb to your computer and use it in GitHub Desktop.
Save Ran-ying/4ef4aa1b097081eae204a3a4c9b85aeb to your computer and use it in GitHub Desktop.
let repeatSpace = (n, ret = "") => {
while(--n >0) ret += " "; return ret;
}
window.onload = ()=>{
document.querySelectorAll("h1, h2, h3, h4").forEach((value)=> {
document.getElementById("sidebar_toc").innerHTML +=
`${repeatSpace(value.tagName.substring(1))}<a href="#${value.id}">${value.innerHTML}</a><br>`;
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment