Created
December 26, 2022 11:21
-
-
Save waldyrious/8eea1db826e9890373a127415c70d3d3 to your computer and use it in GitHub Desktop.
Bookmarklet to add visible anchors to section headings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by https://attacomsian.com/blog/deep-anchor-links-javascript | |
// How to use: Create a new browser bookmark with the code below as the URL. | |
// See https://www.freecodecamp.org/news/what-are-bookmarklets/ | |
// for more background and detailed instructions. | |
javascript:document.querySelectorAll('h2[id], h3[id], h4[id], h5[id], h6[id]').forEach(heading => { | |
let anchor = document.createElement('a'); | |
anchor.href = '#' + heading.getAttribute('id'); | |
anchor.innerText = '#'; | |
anchor.style = 'margin-left: 0.3em'; | |
heading.appendChild(anchor); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment