Skip to content

Instantly share code, notes, and snippets.

@Riksi
Created July 27, 2023 10:39
Show Gist options
  • Save Riksi/0b30db82e12d62768baa068409c9818c to your computer and use it in GitHub Desktop.
Save Riksi/0b30db82e12d62768baa068409c9818c to your computer and use it in GitHub Desktop.
Script to link footnotes back to text in Paul Graham's essays
// 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