Created
November 12, 2020 21:05
-
-
Save tomhodgins/db4d3b8eea4598aa150ba490052f3b0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function html(strings, ...expressions) { | |
return document.createRange().createContextualFragment( | |
strings.reduce((output, string, index) => | |
output + expressions[index - 1] + string | |
) | |
) | |
} | |
document.body.append( | |
html` | |
<style> | |
[data-overview] { | |
position: fixed; | |
top: 0; | |
left: 0; | |
background: rgba(255, 255, 255, .8); | |
padding: 1em; | |
max-height: 100vh; | |
overflow-y: auto; | |
} | |
[data-overview] a { | |
color: black; | |
} | |
:target { | |
background: rgba(255, 255, 0, .1); | |
} | |
</style> | |
<nav data-overview> | |
<ul> | |
${ | |
Array.from( | |
document.querySelectorAll('[id]'), | |
({id}) => `<li><a href="#${id}">${id}</a>` | |
).join('') | |
} | |
</ul> | |
</nav> | |
` | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment