Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created January 10, 2026 19:59
Show Gist options
  • Select an option

  • Save nbogie/b5dbf7f6392cdc013484a85de642033a to your computer and use it in GitHub Desktop.

Select an option

Save nbogie/b5dbf7f6392cdc013484a85de642033a to your computer and use it in GitHub Desktop.
make an insert a rough ToC for p5 tutorials.
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);
})();
@nbogie
Copy link
Author

nbogie commented Jan 10, 2026

rough. ai generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment