Skip to content

Instantly share code, notes, and snippets.

@iamsilk
Created February 2, 2023 18:55
Show Gist options
  • Select an option

  • Save iamsilk/be7b0c1116201d7390095f3b0eb5b3b9 to your computer and use it in GitHub Desktop.

Select an option

Save iamsilk/be7b0c1116201d7390095f3b0eb5b3b9 to your computer and use it in GitHub Desktop.
For use in Firefox's PDF viewer. Dumps subsection titles and page numbers for a given PDF section. Used simply in the browser console.
chapter = document.getElementById("heretakeme"); // choose element somehow
chapterText = chapter.querySelector('a').innerText;
chapterLink = chapter.querySelector('a').href;
chapterPage = parseInt(decodeURI(chapterLink).split("#[")[1]) + 1;
chapterDump = "";
chapterDump += "Introduction" + "\t" + chapterPage + "\n";
sections = chapter.children[2].children;
for (var i = 0; i < sections.length; i++) {
let section = sections[i];
let sectionText = section.querySelector('a').innerText;
let sectionLink = section.querySelector('a').href;
let sectionPage = parseInt(decodeURI(sectionLink).split("#[")[1]) + 1;
chapterDump += sectionText + "\t" + sectionPage + "\n";
}
console.log(chapterDump);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment