Created
July 27, 2023 10:39
-
-
Save Riksi/0b30db82e12d62768baa068409c9818c to your computer and use it in GitHub Desktop.
Script to link footnotes back to text in Paul Graham's essays
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
// Open the console and paste this code into it. | |
// Get all the text links to footnotes | |
const textLinks = document.querySelectorAll('a[href^="#f"]'); | |
// Iterate over each text link | |
textLinks.forEach((link) => { | |
// Get the footnote number from the 'href' attribute of the text link | |
// f{num}n | |
let href=link.getAttribute('href') | |
const footnoteNum = parseInt(href.match(/#f(\d+)n/)?.[1]) | |
// Add the 'name' attribute to the text link | |
link.setAttribute('name', `t${footnoteNum}n`); | |
// Get the corresponding footnote using the 'name' attribute | |
const footnote = document.querySelector(`a[name="f${footnoteNum}n"]`); | |
// Add the 'href' attribute to the footnote using the text link's 'name' attribute | |
footnote.setAttribute('href', `#t${footnoteNum}n`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment