Skip to content

Instantly share code, notes, and snippets.

@klepas
Created March 21, 2019 02:57
Show Gist options
  • Save klepas/291c0e6543739aa3a453bfaba212c9b0 to your computer and use it in GitHub Desktop.
Save klepas/291c0e6543739aa3a453bfaba212c9b0 to your computer and use it in GitHub Desktop.
Document outliner JS bookmarklet
javascript:(function()%7Bvar numbering%3D0001%2ClinkColor%3D%27%27%2CclickOutside%3Dtrue%2CshowDetails%3Dfalse%2Ci%3D%5B%27%23h5o-outside%2C%23h5o-outside *%7Bbackground-color%3Atransparent%3Bborder%3Anone%3Bborder-radius%3A0%3Bbottom%3Aauto%3Bbox-shadow%3Anone%3Bbox-sizing%3Acontent-box%3Bclear%3Anone%3B%27%2B(linkColor%3F%27color%3A%27%2BlinkColor%2B%27%3B%27%3A%27%27)%2B%27cursor%3Aauto%3Bdirection%3Altr%3Bfloat%3Anone%3Bfont-family%3Asans-serif%3Bfont-size%3Asmall%3Bfont-stretch%3Anormal%3Bfont-style%3Anormal%3Bfont-variant%3Anormal%3Bfont-weight%3Anormal%3Bheight%3Aauto%3Bleft%3Aauto%3Bletter-spacing%3Anormal%3Bline-height%3Anormal%3Bmargin%3A0%3Bopacity%3A1%3Boutline%3Anone%3Boverflow%3Avisible%3Bpadding%3A0%3Bposition%3Astatic%3Bright%3Aauto%3Btext-align%3Aleft%3Btext-decoration%3Anone%3Btext-indent%3A0%3Btext-overflow%3Aclip%3Btext-shadow%3Anone%3Btext-transform%3Anone%3Btop%3Aauto%3Bvertical-align%3Abaseline%3Bvisibility%3Avisible%3Bwhite-space%3Anormal%3Bwidth%3Aauto%3Bword-break%3Anormal%3Bword-spacing%3Anormal%3Bword-wrap%3Anormal%3Bzoom%3Anormal%3B%7D%27%2C%27%23h5o-inside *%3Anot(%5Bhref%5D)%7Bcolor%3Ablack%3B%7D%27%2C%27%23h5o-outside%7Bbackground-color%3Atransparent%3Bbox-sizing%3Aborder-box%3Bdisplay%3Ablock%3Bheight%3A100%25%3Bpadding%3A10px%3Bpointer-events%3Anone%3Bposition%3Afixed%3Bright%3A0px%3Btop%3A0px%3Bmax-width%3A500px%3Bz-index%3A2147483647%3B%7D%27%2C%27%23h5o-inside%7Bbackground-color%3Awhite%3Bborder%3A2px solid black%3Bbox-sizing%3Aborder-box%3Bdisplay%3Ablock%3Bmax-width%3A100%25%3Bmax-height%3A100%25%3Bopacity%3A.9%3Boverflow%3Aauto%3Bpadding%3A10px%3Bpointer-events%3Aauto%3B%7D%27%2C%27%23h5o-inside ol%7Bcounter-reset%3Ali%3Bdisplay%3Ablock%3Bmargin%3A0%3Bpadding%3A0%3B%7D%27%2C%27%23h5o-inside li%7Bcounter-increment%3Ali%3Bdisplay%3Alist-item%3Blist-style-type%3Anone%3Bmargin-left%3A%27%2B(numbering%3D%3D%3D2%3F%272em%27%3A%271.5em%27)%2B%27%3Bposition%3Arelative%3B%7D%27%2C%27%23h5o-inside a%7Bdisplay%3Ainline%3B%7D%27%2C%27%23h5o-inside a%3Ahover%7Btext-decoration%3Aunderline%3B%7D%27%2C%27%23h5o-inside li.h5o-notitle>a%7Bfont-style%3Aitalic%3B%7D%27%5D%3Bif(numbering>0)i.push(%27%23h5o-inside li%3A%3Abefore%7Bcontent%3A%27%2B(numbering%3D%3D%3D2%3F%27counters(li%2C".")%27%3A%27counter(li)%27)%2B%27"."%3Bdisplay%3Ablock%3Bleft%3A-10.5em%3Bposition%3Aabsolute%3Btext-align%3Aright%3Bwidth%3A10em%3B%7D%27)%3Belse i.push(%27%23h5o-inside>ol>li%7Bmargin-left%3A0%3B%7D%27)%3Bfunction l(e)%7Bvar t%3Ddocument.createElement(%27ol%27)%3Bfor(var n%3D0%3Bn<e.length%3Bn%2B%2B)%7Bt.appendChild(c(e%5Bn%5D))%7Dreturn t%7Dfunction c(e)%7Bvar t%3Ddocument.createElement(%27li%27)%3Bvar n%3Ddocument.createElement(%27a%27)%3Bt.appendChild(n)%3Bif(e.heading%3D%3D%3Dnull%7C%7C%2F%5E%5B %5Cr%5Cn%5Ct%5D*%24%2F.test(e.heading.text))%7Bt.className%3D%27h5o-notitle%27%3Bswitch(e.associatedNodes%5B0%5D.nodeName.toLowerCase())%7Bcase%27body%27%3An.textContent%3D%27Document%27%3Bbreak%3Bcase%27article%27%3An.textContent%3D%27Article%27%3Bbreak%3Bcase%27aside%27%3An.textContent%3D%27Sidebar%27%3Bbreak%3Bcase%27nav%27%3An.textContent%3D%27Navigation%27%3Bbreak%3Bcase%27section%27%3An.textContent%3D%27Section%27%3Bbreak%3Bdefault%3An.textContent%3D%27Empty title%27%7D%7Delse n.textContent%3De.heading.text%3Bvar i%3De.explicit%3Fe.associatedNodes%5B0%5D%3Ae.heading%3Bn.href%3D%27%23%27%2Bi.id%3Bn.addEventListener(%27click%27%2Cfunction(e)%7Be.preventDefault()%3Bi.scrollIntoView()%7D%2Cfalse)%3Bif(showDetails)%7Bvar s%3D%27%27%3Bif(e.explicit)s%2B%3D%27<%27%2Be.associatedNodes%5B0%5D.nodeName.toLowerCase()%2B%27>%27%3Bif(e.heading)s%2B%3D%27<h%27%2B -e.heading.rank%2B%27>%27%3Bs%2B%3D%27%2C %27%2Be.associatedNodes.length%2B%27 nodes%27%3Bn.title%3Ds%7Dt.appendChild(l(e.childSections))%3Breturn t%7Dfunction h(e)%7Bthis.parentSection%3Dnull%3Bthis.childSections%3D%5B%5D%3Bthis.firstChild%3Dnull%3Bthis.lastChild%3Dnull%3Bthis.appendChild%3Dfunction(e)%7Be.parentSection%3Dthis%3Bthis.childSections.push(e)%3Bif(this.firstChild%3D%3D%3Dnull)this.firstChild%3De%3Bthis.lastChild%3De%7D%3Bthis.explicit%3De%3Bthis.associatedNodes%3D%5B%5D%7Dfunction p(e)%7Bfunction s(e)%7Bif(c(e))%7Bif(!r.isEmpty()%26%26(b(r.top)%7C%7Cp(r.top)))%7B%7Delse if(p(e))%7Br.push(e)%7Delse if(v(e))%7Bif(t!%3D%3Dnull)%7Bif(a(n))l(n)%3Br.push(t)%7Dt%3De%3Bn%3Dnew h(true)%3Bu(t%2Cn)%3Bt.appendSection(n)%7Delse if(d(e))%7Bif(t!%3D%3Dnull)r.push(t)%3Bt%3De%3Bt.parentSection%3Dn%3Bn%3Dnew h(true)%3Bu(t%2Cn)%3Bt.appendSection(n)%7Delse if(t%3D%3D%3Dnull)%7B%7Delse if(b(e))%7Bif(a(n))n.heading%3De%3Belse if(f(t.lastSection)%7C%7Ce.rank>%3Dt.lastSection.heading.rank)%7Bn%3Dnew h(false)%3Bn.heading%3De%3Bt.appendSection(n)%7Delse%7Bvar i%3Dn%3Bwhile(e.rank>%3Di.heading.rank)i%3Di.parentSection%3Bn%3Dnew h(false)%3Bn.heading%3De%3Bi.appendChild(n)%7Dr.push(e)%7D%7D%7Dfunction o(e)%7Bif(c(e))%7Bif(!r.isEmpty()%26%26e%3D%3D%3Dr.top)r.pop()%3Belse if(!r.isEmpty()%26%26(b(r.top)%7C%7Cp(r.top)))%7B%7Delse if(!r.isEmpty()%26%26v(e))%7Bif(a(n))l(n)%3Bt%3Dr.pop()%3Bn%3Dt.lastSection%3Bfor(var i%3D0%3Bi<e.sectionList.length%3Bi%2B%2B)%7Bn.appendChild(e.sectionList%5Bi%5D)%7D%7Delse if(!r.isEmpty()%26%26d(e))%7Bif(a(n))l(n)%3Bn%3Dt.parentSection%3Bt%3Dr.pop()%7Delse if(v(e)%7C%7Cd(e))%7Bif(a(n))l(n)%3Bt%3Dnull%3Bn%3Dnull%7D%7Dif(e.associatedSection%3D%3D%3Dnull%26%26n!%3D%3Dnull)u(e%2Cn)%7Dfunction u(e%2Ct)%7Bt.associatedNodes.push(e)%3Be.associatedSection%3Dt%7Dfunction a(e)%7Breturn e.heading%3D%3D%3Dundefined%7Dfunction f(e)%7Breturn e.heading%3D%3D%3Dnull%7Dfunction l(e)%7Be.heading%3Dnull%7Dfunction c(e)%7Breturn e.nodeType%3D%3D%3D1%7Dfunction p(e)%7Breturn e.hidden%7Dfunction d(e)%7Breturn%5B"blockquote"%2C"body"%2C"details"%2C"dialog"%2C"fieldset"%2C"figure"%2C"td"%5D.indexOf(e.nodeName.toLowerCase())!%3D%3D-1%7Dfunction v(e)%7Breturn%5B"article"%2C"aside"%2C"nav"%2C"section"%5D.indexOf(e.nodeName.toLowerCase())!%3D%3D-1%7Dfunction m(e)%7Breturn d(e)%7C%7Cv(e)%7Dfunction g(e)%7Breturn%5B"h1"%2C"h2"%2C"h3"%2C"h4"%2C"h5"%2C"h6"%5D.indexOf(e.nodeName.toLowerCase())!%3D%3D-1%7Dfunction y(e)%7Breturn"hgroup"%3D%3D%3De.nodeName.toLowerCase()%7Dfunction b(e)%7Breturn g(e)%7C%7Cy(e)%7Dfunction w(e)%7Bif(m(e))S(e)%3Belse if(g(e))T(e)%3Belse if(y(e))N(e)%3Belse E(e)%7Dfunction E(e)%7Be.associatedSection%3Dnull%7Dfunction S(e)%7BE(e)%3Be.sectionList%3D%5B%5D%3Be.firstSection%3Dnull%3Be.lastSection%3Dnull%3Be.appendSection%3Dfunction(e)%7Bthis.sectionList.push(e)%3Bif(this.firstSection%3D%3D%3Dnull)this.firstSection%3De%3Bthis.lastSection%3De%7D%7Dfunction x(e)%7BE(e)%3BObject.defineProperty(e%2C"depth"%2C%7Bget%3Afunction()%7Bvar t%3De.associatedSection%3Bif(t%3D%3D%3Dnull)return undefined%3Bvar n%3D1%3Bwhile(t%3Dt.parentSection)%2B%2Bn%3Breturn n%7D%2Cconfigurable%3Atrue%2Cenumerable%3Atrue%7D)%7Dfunction T(e)%7Bx(e)%3Be.rank%3D-parseInt(e.nodeName.charAt(1))%3Be.text%3De.textContent%7Dfunction N(e)%7Bx(e)%3Bfor(var t%3D1%3Bt<%3D6%3Bt%2B%2B)%7Bvar n%3De.getElementsByTagName("h"%2Bt)%3Bif(n.length>0)%7Be.rank%3D-t%3Be.text%3Dn%5B0%5D.textContent%3Bbreak%7D%7Dif(e.rank%3D%3D%3Dundefined)%7Be.rank%3D-1%3Be.text%3D""%7D%7Dvar t%3Dnull%3Bvar n%3Dnull%3Bvar r%3D%7BlastIndex%3A-1%7D%3Br.isEmpty%3Dfunction()%7Breturn r.lastIndex%3D%3D%3D-1%7D%3Br.push%3Dfunction(e)%7Br%5B%2B%2Br.lastIndex%5D%3De%3Br.top%3De%7D%3Br.pop%3Dfunction()%7Bvar e%3Dr.top%3Bdelete r%5Br.lastIndex--%5D%3Br.top%3Dr%5Br.lastIndex%5D%3Breturn e%7D%3Bvar i%3De%3Be%3Awhile(i)%7Bw(i)%3Bs(i)%3Bif(i.firstChild)%7Bi%3Di.firstChild%3Bcontinue e%7Dwhile(i)%7Bo(i)%3Bif(i%3D%3D%3De)break e%3Bif(i.nextSibling)%7Bi%3Di.nextSibling%3Bcontinue e%7Di%3Di.parentNode%7D%7D%7Dif(!window.h5o_sdWoNJpsAgQGAaf)window.h5o_sdWoNJpsAgQGAaf%3Dfunction()%7Bdocument.removeEventListener(%27click%27%2Ch5o_sdWoNJpsAgQGAaf%2Cfalse)%3Bdocument.body.removeChild(document.getElementById(%27h5o-outside%27))%7D%3Bif(document.getElementById(%27h5o-outside%27))%7Bh5o_sdWoNJpsAgQGAaf()%3Breturn%7Dvar s%3Ddocument.createElement(%27div%27)%3Bs.id%3D%27h5o-outside%27%3Bvar o%3Ddocument.createElement(%27style%27)%3Bs.appendChild(o)%3Bdocument.body.appendChild(s)%3Bfor(var u%3D0%3Bu<i.length%3Bu%2B%2B)%7Btry%7Bo.sheet.insertRule(i%5Bu%5D.replace(%2F%3B%2Fg%2C%27 !important%3B%27)%2Cu)%7Dcatch(a)%7B%7D%7Dvar f%3Ddocument.createElement(%27div%27)%3Bf.id%3D%27h5o-inside%27%3Bif(clickOutside)%7Bf.addEventListener(%27click%27%2Cfunction(e)%7Be.stopPropagation()%7D%2Cfalse)%3Bdocument.addEventListener(%27click%27%2Ch5o_sdWoNJpsAgQGAaf%2Cfalse)%7Dp(document.body)%3Bif(!document.body.sectionList)return%3Bf.appendChild(l(document.body.sectionList))%3Bs.appendChild(f)%7D)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment