Skip to content

Instantly share code, notes, and snippets.

@willbchang
Created October 18, 2022 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willbchang/cbcf2d18ef5d67d9f77bade54fba4ce1 to your computer and use it in GitHub Desktop.
Save willbchang/cbcf2d18ef5d67d9f77bade54fba4ce1 to your computer and use it in GitHub Desktop.
// https://developer.chrome.com/docs/devtools/overview/
// Get Nav Tree as Org Mode Headings
const navtree = document.querySelector('navigation-tree .direction-column')
const title = [...navtree.children].map(getInnerText)
.join('\n')
// You HAVE TO click the webpage after run this code in console.
setTimeout(async () => {
await window.navigator.clipboard.writeText(title)
}, 3000)
function getInnerText(element) {
return {
'A': () => generateOrgH1(element),
'BUTTON': () => generateOrgH1(element),
'DIV': () => generateOrgH2(element),
}[element.tagName]()
}
function generateOrgH1(aElement) {
return '* ' + aElement.getElementsByTagName('span')[0].innerText
}
function generateOrgH2(aElement) {
const subNavtree = [...aElement.children]
return subNavtree.map(a => '*' + generateOrgH1(a))
.join('\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment