Created
January 10, 2026 19:59
-
-
Save nbogie/b5dbf7f6392cdc013484a85de642033a to your computer and use it in GitHub Desktop.
make an insert a rough ToC for p5 tutorials.
This file contains hidden or 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
| javascript:(function(){ | |
| const main = document.querySelector('main'); | |
| const headers = document.querySelectorAll('h1, h2'); | |
| if (!main || headers.length === 0) return; | |
| const ol = document.createElement('ol'); | |
| ol.style.cssText = 'background:#f4f4f4; border:1px solid #aaa; padding:20px 40px; margin-bottom:20px; font-family:sans-serif;'; | |
| headers.forEach((h, i) => { | |
| if (!h.id) h.id = 'toc-idx-' + i; | |
| const li = document.createElement('li'); | |
| li.style.marginLeft = h.tagName === 'H2' ? '20px' : '0'; | |
| const a = document.createElement('a'); | |
| a.href = '#' + h.id; | |
| a.innerText = h.innerText; | |
| li.appendChild(a); | |
| ol.appendChild(li); | |
| }); | |
| main.prepend(ol); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rough. ai generated.