Guest User

Untitled

a guest
Apr 26th, 2026
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.62 KB | Source Code | 0 0
  1.   <script>
  2.   // create array containing content and ID of footnotes
  3.   const footnotes = document.querySelectorAll("section.footnotes ol li")
  4.   const inlineNotes = Array.from(footnotes)
  5.   .map((footnote) => {
  6.     const inlineNote = document.createElement("span");
  7.     inlineNote.id = footnote.id;
  8.     inlineNote.innerHTML = footnote.innerHTML;
  9.     inlineNote.querySelector(".footnote").remove() // remove the link back to the main text
  10.     // style the footnote text
  11.     inlineNote.style.fontSize = "0.8em";
  12.     return inlineNote;
  13.   })
  14.  
  15.   inlineNotes.forEach((note) => {
  16.     // find the footnote's reference in the text
  17.     const fnNumber = note.id.split("-")[1] // as bearblog renders as fn-1 fn-2 etc
  18.     const fnRef = document.querySelector(`#fnref-${fnNumber}`)
  19.  
  20.     // move footnote to reference and then hide
  21.     fnRef.insertAdjacentElement("afterend", note);
  22.     note.style.display = "none";
  23.  
  24.     // change the reference from being a link to the bottom of the page into
  25.     // a clickable toggle
  26.     fnRef.innerHTML = "<a>aside</a>"; // or `<a>${fnNumber}</a>` to retain enumeration
  27.     // style to appear link-like
  28.     fnRef.style.cursor = "pointer";
  29.     fnRef.style.textDecoration = "underline #1a8fe3"; // magic number -- ideally move this styling into the CSS and use the --color-primary variable
  30.     fnRef.addEventListener("click", () => {
  31.       if (note.style.display === "block") {
  32.       note.style.display = "none";
  33.       } else {
  34.         note.style.display = "block";
  35.       }
  36.       })
  37.  
  38.     })
  39.     // remove footnotes from end of post
  40.     document.querySelector("section.footnotes").remove()
  41.   </script>
  42.  
Advertisement
Add Comment
Please, Sign In to add comment